Disable/Change gravity effects on inclined platforms

Hello,

How can I disable or change gravity effects on inclined platforms to make these things happen in my 2D platformer game :

  1. When the object is stopped on a inclined platfrom, it will stay stopped (I disabled the rotation).
  2. When the player walks in a ramp or something similar, it will keep the same speed and will not leave the platform’s surface.

What you are looking for is the “Physics.gravity” variable.

So, lets say you want jump up to a platform above your head. When you are a certain distance away. You change the Physics.gravity.

See: Unity - Scripting API: Physics.gravity for more information on gravity.

I assume you’re using a Rigidbody2D for your character. In that case, one of the variables is “gravityScale”. Setting that to 0 causes the rigidbody to ignore gravity, allowing it to not slide down the platform.

If you import the default asset “Characters” and have a look at the scripts on the First Person Controller, it has a method built-in to keep the player stuck to surfaces. It may be worth having a look at.