- Home /
Why can't the Physics Locomotion System walk up stairs/inclines?
I am having a lot of trouble getting the Planet Scene, Physics/rigidbody Locomotion System character (Hero), to climb a primitive set of stairs. The problem seems to be the capsule collider getting caught on each step and the permanent gravity force pushing down. I am using a clean, new copy of the Planet scene from the Locomotion Demo, and for the stairs I have simply arranged several cubes together.
The character will struggle to climb the first two steps, and after that will not go any higher unless jumping. I am after getting behaviour like in the Crate Climb demo, but with a rigidbody driven character (not character controller), is this possible?
The things I have tried:
Adjusting the Max Step height, Max slope angle and the Tilt Amounts
Raising the bottom of the capsule collider
Copying the Leg Animator settings from the Crate Climb scene
Turning off Centric Gravity
Testing with a ramp
Writing a new rigidbody motor (uses a raycast to tell if grounded)
Writing a second rigidbody motor (uses OnCollisionEnter to tell if grounded)
If I use the same Stairs prefab in the Crate Climb scene the character has no problems getting to the top. Surely you're not restricted to just the CC for climbing elevated surfaces. Has anybody else experienced similar troubles with the Physics Locomotion System like this? Please let me know how to resolve this, as I plan to use the same setup for my own character.
Planet Scene - Using Capsule Collider:
Crate Climbing Scene - Using Character Controller:
Ramp Test - Same incline as stairs
SOLVED - See the inspector for the settings
[1]: http://i44.photobucket.com/albums/f7/whoopiecushion55/PhysicsStairs.jpg
Answer by Hamesh81 · Feb 25, 2012 at 03:53 PM
Seriously, I would rewrite/make your own motor. I remember testing the Locomotion System's physics motor back in the day and it was quite a terrible system for anything other than using centric gravity. Very impractical for any movement over non-flat surfaces, which seems kinda ironic actually. If you don't wanna write a motor script from scratch try changing the way gravity is handled. For example, only apply gravity when the character is not grounded. Also, try making the capsule radius wider which will make the bottom rounder and less likely to get caught on your steps.
The main problem you're having is that the forward force (when walking, running etc) is competing with the gravity force whenever there is any sort of incline. Meaning if the force driving your character forward is less than the gravity force pulling it down, it can never generate enough speed to climb the surface. You could see this when you turned off gravity and it had no problems climbing. Another test you could do is set gravity to 0.1, walk up your steps and when you get stuck try holding shift to start running, it should start climbing. This is because the added boost from the run is enough to over power the weaker gravity force. Anyway, see how you go.
Thank you for your advice. I wrote a new rigidbody motor script (see in the question above) and it definitely solved the gravity issue. Unfortunately that is only part of the problem. The other problem is the raycast and its position relative to the character's feet. Since when climbing up the stairs the feet are positioned in front of the capsule collider and the ray being cast, the ray and capsule are always about one step behind the feet and therefor give inaccurate results. You can clearly see this in the diagrams above.
In all honesty it feels like this system is quite broken. I don't want to sound negative but there is very little to no documentation about the physics setup, and considering it is an official Unity resource, making even the most $$anonymous$$imal of changes shouldn't be such laborious task. Not really sure where to go from here.
Don't know about 'broken', but there defs isn't much info about setting up a rigidbody based locomotion system. Like I said, I didn't find it particularly useful for uneven surfaces and ended up making my own system from scratch. You probably don't want to hear this, but there could be a better way for doing the motor script you tried above. Try giving these two a try first and if you still have problems let me know:
http://www.unifycommunity.com/wiki/index.php?title=PhysicsFPSWalker
http://www.unifycommunity.com/wiki/index.php?title=RigidbodyFPSWalker
After extensive testing and modifying I have finally managed to SOLVE this. So glad it is over, at least this part anyway :)
You were right, it was the motor (or rather the raycast it was using) that was causing the final problem. Using OnCollisionEnter works perfectly now. Thank you so much for your help @Hamesh81, really glad you saw my question.
Glad you figured it out! A rigidbody setup is a bit harder than a CC setup intially imo, but once everything falls in place it is much more flexible and easier to do awesome things with. Good luck with the rest of it.
Answer by junaum · Feb 23, 2012 at 04:23 PM
Try reducing the radius of the capsule collider and increasing the depth of each stair step (make each step farther from each other). It seems that the capsule is touching the current stair step AND the next one, in the same time, causing it to think you are on a really steep cliff.
Thank you for your advice. I made the capsule collider a lot thinner, however this is still causing problems. I've added two images in the question, comparing the physics system and the character controller. The depth of the stairs should not matter so much since the character controller can climb the same stairs without a problem (once it's slope limit is raised). If there were a slope limit setting on the capsule collider I think this would solve the problem. What are your thoughts?
The depth of the stairs (horizontal distance between each stair step) might indeed mean something on this case (if the capsule can climb an slope equivalent to your stair step, then the problem is just the fact that the capsule is being forced to deal with 2 steps in the same time, because they are too close to each other).
Sure, I understand what you mean. It just seams a little strange that the Capsule Collider can't walk up the same incline that the Character Controller has no trouble with. I realize they handle the incline a little differently, but they're both still using the Locomotion System.
I tested what you suggested and placed a ramp with the same incline as the stairs (an image of the result is in the question above). The ramp seems to be causing the same problems that the stairs had. Could it be something to do with the gravity being applied to the Rigidbody? Since in the Crate Climb example that Character Controller has no gravity applied to it. Other than that the only difference between the two setups I can see is that the Character Controller is higher of the ground than the Capsule Collider.
Looks to me like an issue with the height of the capsule collider. In the crate example the CC is positioned a bit above the feet, which allows the character to 'glide' more easily over the steps as the locomotion system climbs its way up. The capsule collider is right on the ground which means the steps are higher and harder for it to climb. Raise the capsule up a bit.
The capsule collider can't be raised because it is held down by gravity, so when simulating the game it will drop to the ground no matter how high it is positioned before hand. I have managed to climb the ramp by turning off gravity, but that isn't a very good solution. Surely there's a way to do this, isn't the purpose of the locomotion system to walk on uneven surfaces? Or should I be looking for an alternative system if using a physics based character? Any advice welcome :)