Constant Force to pull a sprite

0 favourites
  • 6 posts
From the Asset Store
Build a thrilling space station scenario with these level assets and characters.
  • Hi all, completely new to Construct 2, and have no advanced math or programming knowledge.

    I'm trying to create a Star Castle type game, where you fly a spaceship around the center of a map which contains a starbase. There's a constant pull towards that center that requires the player to maintain a sprint and drift type playstyle to avoid being smashed into the shields around the base.

    I've read a couple of threads and downloaded a couple of examples, but I have no clue what I'm looking at. The examples I read had to do with gravitational pull and mass relationships and require setting up calculations and variables that are way over my head.

    All I need to know is if it's possible to set up a simple constant pull that can be overcome by acceleration and steering. If it requires sin and cosin calculations and a lot of variables, I'll drop it.

    If I can do it with just an event or two with force or impulse, I'll keep working on it.

    I've tried putting a sprite in the center of the map and set

    various impulse and force amounts to the x,y coordinates of the sprite, but it causes behavior that doesn't make any sense. The player begins falling, spinning, or moves so fast that there's no chance to move.

    Any advice at all would be greatly appreciated.

  • You can try something like this. Then, on collision you can destroy your ship and game over :)

  • MarkP - here is a range based gravity system i helped someone else with. basically (it's all based on the value set for the instance variable range of the object "sun" so you only need to change it once to change all this code) it applies more gravity the closer the player gets to the planet (or sun).

    it checks for the distance between the player and sun and applies gravity (force) accordingly.

    <img src="https://dl.dropbox.com/s/4hpqu53fjysm0rj/gravity.jpg" border="0" />

  • You can try something like this. Then, on collision you can destroy your ship and game over :)

    http://imageshack.us/photo/my-images/5/forcetowards.png/

    Ok, great. I was making the event incorrectly. (back asswards)

    I'm assuming that Sprite8 would be the base and Player of Player.X,Y would be the players ship?

    I was trying to set it up where sprite 8 was the player and Player.X, Y was the base. Looks like I was trying to pull an immoveable object with my ship and that's what was confounding me.

    I'll try it out as soon as I get time, much obliged.

    wretchedshark, thanks for that info, I'll keep it as a reference.

  • Yeah, sorry. I forgot to explain that Sprite8 is your Ship and Player is the sprite that will pull your ship towards it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • For anyone reading this having the similiar trouble of the sprite spinning around without input, check the image point. If it's not precisely centered, you will be applying force at an angle that causes the sprite to spin like a top. The higher the force or the faster your acceleration away from the pulling sprite, the worse the spin.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)