- Home /
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 :
When the object is stopped on a inclined platfrom, it will stay stopped (I disabled the rotation).
When the player walks in a ramp or something similar, it will keep the same speed and will not leave the platform's surface.
I'd say don't use Unity's gravity, make your own one :)
It's the same thing. There is a force pushing the object down and when it's on an inclined plaftorm it keeps descending.
Answer by Mulldor · Jul 22, 2015 at 01:45 PM
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: http://docs.unity3d.com/ScriptReference/Physics-gravity.html for more information on gravity.
Physics.gravity changes the gravity for every object in the whole scene, not just the player on the ramp. That might not provide the intended effect :P
Answer by alexi123454 · Jul 22, 2015 at 01:54 PM
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.
Your answer
Follow this Question
Related Questions
how i can make my player lose 1 live after HP = 0 ? 0 Answers
How Can I Make A Platform Lauch My PLayer Into The Air? 2 Answers
Make box tip over edge of platform 1 Answer
Player parent to platform problem 0 Answers
How to make a 2D spritesheet 1 Answer