- Home /
how to climb slopes without slipping the rigidbody?
I'm programming a game in 2d and I would very much like to find a formula that is simple and efficient to get the character to recognize the slopes and go up and down without slipping, I've searched a lot on the internet for something that can help but not successful still, if anyone can help me thank you too much!
I already found many similar doubts but I still did not find one that would answer me because I am relatively new with programming still.
Well, are you using any physics engine? Are you calculating the motion all by your code self?
I'm using unity physics with rigidbody2D, I'm moving the character with Rigidbody.velocity
Would it help to apply a lot of friction to the character?
Answer by Lucasr07 · Jun 04, 2019 at 05:28 PM
Sorry if I'm not clear, I'm using google translate to communicate, because Brazilian and there is no material to study that explains it.
this video shows in practice what I would like to achieve: https://www.youtube.com/watch?v=cwcC2tIKObU
The explanation seems very complex, I tried to do it but I did not succeed.
explaining once more in detail: I have a character body that uses Rigidbody.velocity to move around and its collisor is a capsule. Both the character and the Ground have no friction material. When I go through inclinations I get too much to climb, and I slide when I stop adding speed. So what I would like to achieve would be basically a way to detect the slope of the ground and stabilize the body on top of it, so I can climb up and down without grabbing or slipping, as in platform games like Super Mario, Donkey Kong Country. I've been trying for a long time for a solution and thank you very much if anyone can help me!
Answer by Pangamini · Jun 05, 2019 at 08:28 AM
Well... if detection of the slope is what you want, then perhaps you could find out what are you colliding with, using OnCollisionEnter() and somehow decide if it's a slope or not. Since I am not sure about your game mechanic, whether slope is a special place (and the character is climbing it eg. with arope or a pickaxe) or if it's just a sloped surface where the character walks normally) it's up to you to define the slope. Could be a gameObject somehow explicitly marked to be a slope (having a component, name, tag, etc) or it could simply be any sloped surface, in which case you would be interested in the collision normal, a vector pointing away from the surface you are standing on. You could then see how much this normal deviates from UP vector (by using Vector dot product / )
BUT, if you are not really all that interested in detection of the slope and you simply want to walk on it without slipping, while keeping all the normal character's behaviour (and physics properties) thenthe easiest solution would be to add a strong friction to the character's collider (or perhaps the slope collider or both)
Actually I've tried using tags to detect if it's a slope or not but I did not get the results I wanted. The inclinations I refer to are common slopes in platform games that exist in any 2D game, would be basically deformations in the ground, for$$anonymous$$g mountains and descents. On the friction already tried also but then the body is unable to move normally due to the friction, I even tried to create a boolean to activate the friction only when I am stopped, but all these solutions palliative give a very amateur result. Well, anyway thank you very much for the tips, I'll go and try to see if I can get any ideas for this.
Your answer
Follow this Question
Related Questions
Rigidbody2D climbing 45 degrees slopes 2 Answers
Handling Slopes 0 Answers
problem with 2d movement down slopes 0 Answers
Rigidbody2D jumping off of slopes 0 Answers
Lerp doesnt seem to work 1 Answer