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

Maybe after 5 years he’s figured it out ;-D
I’m just kidding. Would you mind sharing your solution?

Try this script, it is a sample of what I have made so far regarding the step problem…The caracter should look like this. Hope it helps, feel free to modify it and improve it :smile:

Check out the script first before doing anything cause it is a full character controller script with movement, jump and crouch just like the sample from unity 3d standard assets, however this one can handle steps and slopes by creating a “suspension effect” on surface.

3086590–232564–TPRB.cs (2.4 KB)
3086590--232567--Captura de pantalla 2017-05-28 a las 23.05.43.png

try this script

•using UnityEngine;
•using System.Collections;

•public class MoneySystem : MonoBehaviour {
•//an internal reference to the system itself
• private static MoneySystem _instance;

•//current balance
• public int money;

•//interval for saving the money to Playerprefs
• public float saveInterval;

•//internal variable which uses getters and setters to ensure that the money system is ALWAYS available.
• private static MoneySystem instance
• {
• get
• {
•//if the instance is null, first make sure there’s not already a gameobject named MoneySystem. If there is, check for the
•//MoneySystem component and set it as instance, otherwise add the component and set the new one as instance.
•// If there isn’t a gameobject named MoneySystem, make one and add the MoneySystem component.
•//Lastly, return the instance.
• if (_instance == null)
• {
• if (GameObject.Find(“MoneySystem”))
• {
GameObject g = GameObject.Find(“MoneySystem”);
• if (g.GetComponent())
• {
• _instance = g.GetComponent();
• }
• else
• {
• _instance = g.AddComponent();
• }
• }
• else
• {
GameObject g = new GameObject();
• g.name = “MoneySystem”;
• _instance = g.AddComponent();
• }
• }

• return _instance;
• }


• set
• {
• _instance = value;
• }
• }

• void Start()
• {
•//Make sure the Gameobject is named MoneySystem.
• gameObject.name = “MoneySystem”;

• _instance = this;

•//load the saved money
• AddMoney(PlayerPrefs.GetInt(“MoneySave”, 0));

•//start the save interval.
StartCoroutine(“SaveMoney”);
• }

•//while reality exists, save money every saveInterval.
• public IEnumerator SaveMoney()
• {
• while (true)
• {
• yield return new WaitForSeconds(saveInterval);
PlayerPrefs.SetInt(“MoneySave”, instance.money);
• }
• }

•//Checks if you have enough money to buy item with cost, if you do buy it and return true. Otherwise, return false.
• public static bool BuyItem(int cost)
• {
• if (instance.money - cost >= 0)
• {
• instance.money -= cost;
• return true;
• }
• else
• {
• return false;
• }
• }

•//Simply return the balance
• public static int GetMoney()
• {
• return instance.money;
• }

•//Add some money to the balance.
• public static void AddMoney(int amount)
• {
• instance.money += amount;
• }
•}

I just ran into the same problem that my character could not climb any stairs after changing it to a rigidbody controlled by force. The reason is clear. Physics won’t make your body lift just because you hit an obstacle in front. In real life we raise a foot and apply force in the up direction while moving forward.
The solution in the RigidbodyFPSController (standard assets) was surprisingly easy: Roughly following the real life example we just need to find a way to raise the rigidbody at certain circumstances. After testing several methods all I changed was the sphere cast origin in the GroundCheck method. Now the cast is just a little bit shifted in the forward direction (currently I use 0.1 units). That way the height over ground is checked at that distance in front of the character instead of your y-axis. You can think of that as checking at your toes instead of near the heels.
I tested that with stairs, ramps and obstacles of different heights and am very satisfied with the results.

The change in detail is:

        /// sphere cast down just beyond the bottom of the capsule to see if the capsule is colliding round the bottom
        private void GroundCheck()
        {
            m_PreviouslyGrounded = m_IsGrounded;
            RaycastHit hitInfo;
            if (Physics.SphereCast(transform.position + cam.transform.forward * advancedSettings.checkGroundForwardDistance, m_Capsule.radius * (1.0f - advancedSettings.shellOffset), Vector3.down, out hitInfo,
                                   ((m_Capsule.height/2f) - m_Capsule.radius) + advancedSettings.groundCheckDistance, Physics.AllLayers, QueryTriggerInteraction.Ignore))

(here advancedSettings.checkGroundForwardDistance defaults to 0.1f)

I see that this is an old post, but it also seems like ppl are still facing this problem. I came to this thread searching for the same. “How to keep a Rigid body Capsule Collider from sliding down a ramp?”

If your colliders are flat, like a ramp, then giving your player a physics material can keep it from sliding around.

My player would go about .33 U (unity units) up the ramp before gravity would pull it back down, after giving my player the Rubber physics material, he climbs all the way up the stairs.

No Raycast. No code. No Character Controller. No problem.

1 Like

You just saved me precious time

For those of you who are spectacle of why people don’t just use the Character Controller, it may just be because they didn’t like the feel of it. It’s physics just don’t feel 100%. Also as advanced as the Character controller maybe, it can’t do everything, and editing the code can be a pain. There are plenty of reasons not to use it. The developer may be making their own character controller for educational purposes, so a pre-made, pre-set character controller isn’t particularly helpful. The developer may already have a character controller they like and that works for the situations they need it to. In that case there is no logical point to scrap an entire character controller just because you want a single feature like Step Offset.

I am by no means saying that the Unity Character Controller is useless or unneeded, I am just saying that not everyone wants/likes it. So instead of accusing people for not liking the same system as you, try finding out why they don’t like it.

1 Like

May I suggest adding a Physic Material to the stairs? Then set the static friction to 1. It worked for me.

Hey All, been watching this thread for solutions and while I applaud you all for your techniques, Zathariel1 came in with the win for me. Using Unity Tech Free Sci-fi asset, I bake the agent types at .5 radius; 2 height; .4 step height; and a 40 max slope on humanoid for the name. The baked agent size is .25, 2, .4, and 60 respectively. The drop and jump are 0. Then I head to my player controller (not the object/child holding the animator but its parent)—using Game Creator—and scroll to the Character Controller component “On the Inspector”! I set slope limit to 90.79 (I like being different) , step offset to 2 and viola. No need for Mixamo and triggers with conditions and variables and mess!!! Hope that helps.

1 Like

the thing is that some people have learnt and understand the rigidbody system more than the chracter controller

Hi there. As there’s no very clear answer, here’s a very easy and clean solution; add a navmesh agent to your player. Just untoggle the auto options and set up the height and slope you want. It works great!

rjakob13 had the best idea by far, you all just didn’t take the time to read it lol or his implementation was more complicated than it needed to be:

if (Physics.Raycast(transform.position - new Vector3(0, .5f, 0), player.transform.TransformDirection(new Vector3(0, -1, 1).normalized), .6f))
        {
            rb.AddForce(new Vector3(0, 5, 0));
        }

This works with a capsule collider and a ramp, it simply casts a ray forward at a 45 degree angle from the base of the capsule to a little bit outside of it and adds a force upwards if it hits something. You may want to add a layermask so not everything causes it. I thought that was clearly the right answer for this. You could even adjust it so it works with actual stair mesh colliders and not just ramps. Then as other people said add the rubber material to your collider so you don’t slide back down. I hate character controllers too.

“Use something completely different” isnt an answer

1 Like

Neither is necroing a thread by replying to a post that is 10 years old.

Please, in the very least, look at the dates of posts you’re responding to.

1 Like

Hi, I am new a coding and my 2d player will not go up slops when there are slops and it will not go down slops. do you guys think you can help?

You are hijacking and necroing an old thread from 2012. Please, just create your own thread and describe what you’ve done so far and what things you need help with. If you are asking for scripts then that’s not what the forums are for. There are lots of tutorials online for this kind of stuff. Search for “Unity 2D character controller”.

Also, note that it’s “slopes” not “slops”.