I Wanna Community

Fangames => Game Design => Programming Questions => Topic started by: AlexGuy on March 23, 2015, 03:13:29 PM

Title: Gravity
Post by: AlexGuy on March 23, 2015, 03:13:29 PM
How can I make an object, that if the player goes through the object, his gravity changes to lower gravity for example? I tried to program an object, but it didn't work. Could someone help me please?
Title: Re: Gravity
Post by: Aelya on March 23, 2015, 06:09:58 PM
what's your code
Title: Re: Gravity
Post by: AlexGuy on March 23, 2015, 06:14:49 PM
what's your code

well, I chosed the object which should change kid's gravity and made collision player and then this creation code: "with(player){gravity = 0.2;}"

simply as that :/
Title: Re: Gravity
Post by: klazen108 on March 23, 2015, 08:18:01 PM
That's because the player sets his gravity back to normal every step (here's a picture from Seph's Engine, but it works the same in all engines):
(https://i.imgur.com/HHUDb4o.png)

To fix it, you need to change that line in the step event to
Code: [Select]
gravity=player_gravity
and add the following to the create event:
Code: [Select]
player_gravity=0.4
Then you can edit your code to be
Code: [Select]
with(player){player_gravity = 0.2;}
And it should work! (Remember to reset player_gravity=0.4 when you're done with it, on game load or room start or game reset etc, or else people can keep their different gravities in places you wouldn't expect!)