- Home /
Player's Rigidbody slides up terrain walls
My player has a rigidbody and a box collider. For some reason, he seems to slide up terrain walls. I move him via Translation, with a movement speed of at least 17 units per second (if that helps). It only takes three or four seconds to slide all of the way up a wall that's like, 6x as tall as my player...
As far as I know, I haven't done anything to the terrain's physics..whatever it has that determines stuff like that. I tried different physic materials, including a custom one with all values set to 0...but nothing got much different results. Also, I reset the rigidbody of the player and nothing different happened (all that had been different was his mass I think, probably when I was trying to figure out a way around this).
Another note, the terrain has been smoothed, but it's still quite steep.
Any help with getting it to not slide up terrain would be greatly appreciated!
Answer by syclamoth · Sep 16, 2011 at 06:40 AM
Well, Translation isn't really subject to physics- your character will do their best to move forward, and since Terrain objects (which I assume is what you mean by terrain) can never be perfectly vertical, that means sliding straight up! Have a look at using rigidbody physics instead, if you don't want your character doing strange stuff when interacting with other colliders.
Thanks. I thought of trying rigidbody.AddForce() ins$$anonymous$$d of transform.Translate, but I'm not sure how the function works. Does it add the force and leave it there every time the function is called, or is it like Translate and has to be called continuously to keep the momentum going?
Rigidbody.AddForce makes one push on your rigidbody- it does not persist longer than one frame. However, it should be noted that since it adds a force ins$$anonymous$$d of just changing an object's position, the object in question will continue to move as long as there is no friction or other force acting on it to slow it down! Implementing objects that move at a constant speed and stop and start instantly is a little difficult to do with rigidbodies, because it is a behaviour that doesn't reflect reality very well. The most realistic way to stop an object from moving too fast, is to set its drag to something reasonably high, and then calling Rigidbody.AddForce every FixedUpdate- this results in an object accelerating until the drag forces perfectly cancel out the incident force, and the object remains at a constant velocity.
EDIT: Which is to say, no, you don't need to call it every frame to "keep the momentum going", but that probably isn't what you want, anyway.
I see..I suppose I should start using rigidbody.AddForce ins$$anonymous$$d. I tried it out, but I'm going to have to rework my formulas a bit. Using the same Transform.Translate formula as I had but with "* Time.deltaTime" taken out, my jump script moved about half the distance it usually would have. The formula I'd been using was:
(JumpHeight / JumpTime) * Time.deltaTime
If you have any suggestions on how to get the rigidbody to smoothly move you the distance provided per second, that would be great. Thanks for all the help you've been, also! :)
EDIT: $$anonymous$$aybe some way of figuring out how long it takes to start moving at the given speed (the build-up time) or something like that...
Well, the way I do it is to have a 'desired speed', and then reduce the amount of force depending on how close to it you are moving. As for the Time.deltaTime thing, you should always always ALWAYS have it in there, otherwise all your physics stop being frame-rate independent!
Your answer
Follow this Question
Related Questions
Terrain collider failing in unity 5/17? 1 Answer
Innacurate terrain collision with fast rigidbody 1 Answer
Object Flies into Air Upon Collision, or goes through hill depending on isKinematic settings 1 Answer
Keep Horizontal Momentum after Jump 2 Answers
Collision.impulse = 0 in OnCollisionStay Kinematic Static collision pair after Update 0 Answers