- Home /
Bouncing ball off wall problem
I'm trying to bounce a ball off a wall, but when I throw the ball towards the wall, it often bounces adjacent to it just up and down.
I had my physics material on the ball set with bounciness at 1, friction at 0, and a max bounciness, min friction.
I've also tried turning off the physics material and adding to the OnCollisionEnter
function with a few things:
private void OnCollisionEnter(Collision collision)
{
Rigidbody rigid = GetComponent<Rigidbody>();
rigid.velocity = Vector3.Reflect(rigid.velocity, collision.contacts[0].normal);
//rigid.AddForce(collision.contacts[0].normal * weight, ForceMode.Impulse);
}
Neither of the above seem to work. Using collision enter gives me -better- results, but still not great.
Any ideas?
Adjust the weight of the ball, the width of the wall, perhaps those are the problems. Also make sure your rigidbody collision detection is set to dynamic on the ball.
In the worst case scenario, if nothing helps, you can try raycasting in the direction of the velocity, and faking the bounce by using the normal vector received in the raycasthit, although this should not be necessary if everything is setup correctly.
Can you please post a picture of the inspector tab of the ball? I have a suspicion...