Gravity different directions

Hello everyone and Happy New Year!
I’m trying to figure out how to switch gravity every time the player switch directions.
For example, if my player walks on the floor, the gravity is set to 1000, but if my player walks on the ceiling the gravity is -1000. How do I set that?

 condition: up key is pressed    Action:Simulate up/ Change Direction/ set gravity 

doesn’t seem to work


This is exactly what I want to achieve!

maybe do - instead (or if its - remove it

If you use the platformer behavior it is not possible to make gravity inverted, sadly.

Where to subtract or remove it?

So what you recommend? Should I use top- down, physics 2.0?? I’m playing with the physics to see if I can get any solution.

Make sure your player character has the PlatformerObject behaviour attached. Then set the gravity of the player to -1000 object via Platform Behaviour > Options > Gravity.

Note, this will only change gravity for the player object, not anything else in the scene.

@MrMen Please read previous posts and verify your answers before posting here… I just said The platformer behavior won’t work with negative gravity.

@arthur555, I tried it on a test scene before posting, and I could change the gravity of a player object with PlatformerObject behaviour attached.

Wait how I tested many times and it also isn’t programatically possible to make gravity negative as the code makes some checks by moving the Sprite a bit up down left and right to guess the collisions better but assuming the ground is underneath the Sprite on the coordinate system and inversed gravity would mess up all the checks

I recommend using the physics 2 behavior while gravity changing in the platformer one is not possible.

Gravity cannot be change to negative in the Platform Behaviour. But you can work it through in the event. I’m working with physics 2 I applied gravity scale, add force, etc. but not solution yet.

Heh, interesting. I created a new platformer game (using the default one when creating a new GDevelop project), and then just added the following line to change player gravity:

Collision still works - I placed a platform above the player, and the player floated up until it collided with the platform.

Or am I barking up the wrong tree?

what I’m trying to do is to being able to control the player movement by gravity. I just want to press up so my player goes up or down so it goes down.

I just tested and as expected with negative gravity:

  1. The hitbox was completely floating above the platform
  2. You can’t jump as the code doesn’t see any ground underneath the Sprite, only above
  3. The animations were messed up as it never considered the player as touching the floor as the floor is above but the code doesn’t know and other animation problems
  4. Weird collisions behavior

What you actually want doesn’t require either gravity or physics, just use the forces actions to add an instance force upwards or downwards. Or did I missunderstood?

EDIT: my bad looking at the original post It is obvious that you want gravity I am just stupid ignore this post

See I tried that, and it works, but I want to be able to just press once, that’s why I wanted to use gravity. If I add an instance force the player would move from pixels to pixels. With permanent force works just perfectly, but the player wont stop.

Ahh, I only tested to check that the player would float and stop when it collided with a platform. I didn’t go so far as to check other movements. My bad.

Maybe something to put on the enhancement/wish list?

1 Like

Maybe there is a way around. I’m just going to keep finding a solution

I might figure out!!!

Global Variable

1 Like

You don’t need to add the variables in that UI, by default if you don’t define it here it is 0.