I tried to make sonic physics and got stuck

I played Freedom Planet the other day and I suddenly decided to try if it was possible to implement similar physics in GDevelop.

What I want:

  • momentum with slopes:
    gaining speed when going down a slope, losing it when going up one.
    So to be, for example, be unable to go up a slope without building momentum first.

  • Walking on walls and ceilings:
    Going up walls if the vertical momentum is superior to the gravity, or if the player character is capable of that.

  • Jumping direction is always perpendicular to the current floor instead of always 90 degree upward.

  • And maybe change the direction of gravity, like in the Death Egg Zone of Sonic & Knuckles, and VVVVVV.

some videos as illustration

I’ve also found this working example, but it’s for Godot

I tried to do it following the guide from sonicretro.org, but I failed, I couldn’t get past the slope physics

Reasons:

  • There’s a limitation on the max slope angle that won’t even allow it to reach 90 degrees.

  • No actions, conditions or parameters related to platformer slopes.

  • Not possible to change the angle of jump. It’s stuck on 90 degree relatively to the scene.

  • Not possible to check the angle of the current floor.
    Sure it is possible to check the angle of the object, but it doesn’t work if the object is upside down, and worse, walls would say that their angle is 0 instead of 90 or -90, and the ceilings would also say 0.
    Have to use collision detection and object variables instead.

  • Not possible to change the axis of gravity. Giving it a negative value doesn’t make the player go up.

I tried using the physics engine but didn’t have more success. I am not very smart :frowning:

I think that my two real problems are the lack of control for vertical acceleration and the limit on the
possible slope angles. Or maybe something else.

Suggestions are welcome.

While I’m not going to be able to give you answers on this directly, it sounds like you might be approaching this from the wrong mindset. As mentioned on your sonicretro page, even in the original engine they just worked by using the object’s height and angle. The slopes being shown in the diagram are calculations, not explicit to the obejct.

  • There’s a limitation on the max slope angle that won’t even allow it to reach 90 degrees.

That is because 90 degrees isn’t a slope angle. 90 degrees means you’re now facing a flat surface (a wall), at that point you need to treat it like any other flat wall (i.e. you need to use jump logic or upward forces)

  • No actions, conditions or parameters related to platformer slopes.

You’d need to provide more detail on what you expect here, platformers themselves don’t have slopes. Maximum slope angle is fixed as it directly relates to collision, as far as I know.

  • Not possible to change the angle of jump. It’s stuck on 90 degree relatively to the scene.

You’d need to provide more detail here, because Jumps don’t have angles at all. They’re just applying upward forces, if you want to move at an angle you’ll need to do the appropriate geometry to apply force in the angle you want to go. or you could fudge it by just simulating the left/right key being pressed slightly.

  • Not possible to check the angle of the current floor.

You can check the angle of any object with the Object.Angle() expression as you mention, this is also accurate because your object’s angle

Sure it is possible to check the angle of the object, but it doesn’t work if the object is upside down, and worse, walls would say that their angle is 0 instead of 90 or -90, and the ceilings would also say 0.
Have to use collision detection and object variables instead.

Why is any of this an issue? If the object is flipped horizontally, just check for that in conditions then multiply its angle by -1 if you want a positive number, or go all the way and add 180 to the number. Ceilings saying 0 wouldn’t matter either since you’re going to have to apply forces to move along a ceiling anyway.

  • Not possible to change the axis of gravity. Giving it a negative value doesn’t make the player go up.

This is accurate, but also not really an issue. As mentioned in the article, Sonic had his own gravity calculation and systems. If you’re using an inverted platform you just need to do your own calculations and apply forces as needed. In most cases to keep “stuck” to a platform you just need to add as much force upwards as equal to your platformer’s gravity parameter.

1 Like

This is how I imagined it:
Condition Current speed = [fast enough]
Action: Change max slope angle to 90

That would have allowed the player character to go up a slope that curves all the way to a 90 degree wall when going fast enough.
Or maybe even
… Action: Change max slope angle to 360
To allow the player to walk on the ceiling.
Keep in mind that I don’t know much about the insides of the engine.

I should just get better at programming.