- Home /
How to stop a rigidbody from bouncing off when colliding
Hello,
i had a problem with my player rigidbody. when it collide with the wall it bounce off this might help to understand.
i'm searching for a way to stop the rigidbody when it reach a wall. i tried that with Raycast but i guess it's slower than the player impact speed. i want the player to just stop moving when it reach a wall. no bounce or walking through it.
My player is rigidbody controller by Add Force
Thanks
Answer by robertbu · Jul 01, 2013 at 05:47 PM
First walking through walls as a result of high velocity (assuming that is an issue for you) is a separate issue from bouncing off walls. There are hundreds of posts on going-through-walls issues. As for stopping, at the collision you can set the IsKematic flag of the rigidbody to true. Or as an alternate, you can set the velocity to Vector3.zero (but gravity will continue to pull the block down). Another way is to make the walls triggers, and set the IsKinematic flag on the trigger.
function OnCollisionEnter(collision : Collision) {
if (collision.collider.tag == "Wall")
rigidbody.isKinematic = true;
}
And if the walls are triggers:
function OnTriggerEnter(collider : Collider) {
if (collider.tag == "Wall")
rigidbody.isKinematic = true;
}
Note there is one frame of movement that occurs despite the code above. For most situations this is not a problem. But if it is, I worked out a couple of hacks:
http://answers.unity3d.com/questions/462907/how-do-i-stop-a-projectile-cold-when-colliding-wit.html
Couldn't a physics material also help here to remove the bounce?
@amphoteik - yes if we are dealing with a simple collision between the wall and the object and if gravity is turned off. Removing the bounce does not stop movement based on other forces such as another rigidbody hitting the object or gravity pulling it down.
@robertbu that's what I thought. I guess I would need more info before knowing if it was a viable solution.
Answer by absolutegames1 · Jul 01, 2013 at 07:33 PM
or maybe try to change the type of material, check if its bouncy(as material)
Your answer
Follow this Question
Related Questions
Creating a teleportation gun 1 Answer
Need help with limiting rotation. 1 Answer
Trouble with RayCast, rigid body and the colliders tag 0 Answers
remove forward component from velocity vector 2 Answers
raycast to object, load wrong script!? 2 Answers