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
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
or maybe try to change the type of material, check if its bouncy(as material)