Constant Force to pull a sprite

Get help using Construct 2

Post » Fri Feb 22, 2013 10:35 am

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.MarkP2013-02-22 10:36:24
B
2
Posts: 3
Reputation: 306

Post » Fri Feb 22, 2013 5:38 pm

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


B
20
S
5
G
3
Posts: 53
Reputation: 3,310

Post » Fri Feb 22, 2013 5:49 pm

@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.

B
14
S
6
G
2
Posts: 136
Reputation: 3,210

Post » Fri Feb 22, 2013 6:00 pm

[QUOTE=donelwero] 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/
[/QUOTE]

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.MarkP2013-02-22 18:01:08
B
2
Posts: 3
Reputation: 306

Post » Fri Feb 22, 2013 6:12 pm

Yeah, sorry. I forgot to explain that Sprite8 is your Ship and Player is the sprite that will pull your ship towards it.
B
20
S
5
G
3
Posts: 53
Reputation: 3,310

Post » Sat Feb 23, 2013 6:24 pm

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.
B
2
Posts: 3
Reputation: 306


Return to How do I....?

Who is online

Users browsing this forum: anty21ro, fr0z3n, LeFuji, newt, RookieDev, TRMG and 19 guests