How to Get a Rigidbody Player to walk on any type of stairs ?

How would I get my rigidbody player to walk on stairs of any height and length. I tried using an invisible ramp over my stairs but the result was pretty unrealistic and the player would fly off the ramp. Please help

[EDIT] : I solved it :smile: or at least it works for me… Since I was checking if the player was grounded by comparing the current slope of the ground with the maxSlope variable and setting grounded (another variable) to true or false as necessary … All I had to do then was to make sure that the current slope of the ground was greater than the maxSlope variable (Since stairs are always stacked upon each other at 90 degrees) and also that the tag of the ground was ā€œStairsā€. If so then the grounded variable would be set to true and the player then happily walks up the stairs :o)

Use a Character Controller instead.

2 Likes

As you pointed out, the correct way of doing it it using an invisible ramp (or at least, most of the games I’ve seen use this trick). It should not be a problem if you don’t have an exaggerated ramp inclination or gravity is not proportional to the player’s size (remember it should be around 2 UnityUnits.

If the problem persists, you could put the ramp into a new layer (let’s say 8) and every time the player raycasts down and sees a ramp, apply some vertical force downwards to make sure he does not fly off. It’s not a very elegant solution though…

Thanks Hasho… I will probably go with that solution but then again if someone has something else then please do tell me.

Zethariel thats the very reason I changed to creating players with rigidbodies :stuck_out_tongue:

Why? A CharacterController has a variable designed SPECIFICALLY to handle stair movement – Step Offset

3 Likes

Really? This is the first time I’ve noticed there was that variable in the CharacterController (maybe because I don’t really use it and I always create my own PlayerController). Anyway, good point.

Because it does not react realistically to physics (at least thats what I think :P)

1 Like

No, it doesn’t, true. Modern games try too hard to be realistic IMO, and (at least that is what I need) not phasing through doors is god enough for me :slight_smile:

2 Likes

By the way, check out the 2D platform game tutorial from lerpz. The controller uses a component to behave like if it was a rigidbody (pushing crates off when the player tries to go through them).

Thats done by a script which adds force to any rigidbody that the player collides with. So its not at all realistic (at least for me :P).

Bump please help

BUMP…

What about the locomotion system here

Actually the player is just an invisible rigidbody capsule :P… So I guess its not going top work :frowning:

Bump…

Is your rigid body kinematic, or are you moving it by applying forces?

Nope its not kinematic. And yes I am moving it by applying forces

Bump

I’m not sure why you’re still bumping… you got your answer: put an invisible ramp on it. If you want ā€œrealisticā€, then if you push a big solid capsule down a set of actual stairs, it does pretty much what it’s doing in game and what you don’t like: it will bounce down the stairs in a really ugly and jittery way. That’s real life. If you want it to smoothly ā€œwalkā€ down stairs, it can’t be a big solid capsule. You’d need to use an IK system like the one linked in the above post that has separate physics on the actual legs, knees, and feet rather than one big capsule.

I have managed to solve this issue with a line that solves not only any type of stairs but also keeps the character attached to the ground, do not miss out, send me an email if you are interested to know how I did it.

It only works with rigidbody + capsule collider at the moment.

ipctbunity@gmail.com