Author Topic: Gravity  (Read 1551 times)

AlexGuy

  • Trial Wannabe
  • Posts: 2
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 41.0.2272.101 Chrome 41.0.2272.101
    • View Profile
  • Playstyle: Keyboard
Gravity
« 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?

Aelya

  • Cherry Eater
  • Posts: 55
  • love~ <3
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 41.0.2272.101 Chrome 41.0.2272.101
    • View Profile
    • stream
  • Playstyle: Keyboard
Re: Gravity
« Reply #1 on: March 23, 2015, 06:09:58 PM »
what's your code

AlexGuy

  • Trial Wannabe
  • Posts: 2
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 41.0.2272.101 Chrome 41.0.2272.101
    • View Profile
  • Playstyle: Keyboard
Re: Gravity
« Reply #2 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 :/

klazen108

  • Administrator
  • The Kid
  • Posts: 286
  • your a kid now your a squid now
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Chrome 41.0.2272.89 Chrome 41.0.2272.89
    • View Profile
    • Delicious-Fruit
  • Playstyle: Keyboard
Re: Gravity
« Reply #3 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):


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!)