I am having some issues with making a ball bounce off walls in 3d unity.
Below is my code:
My fixedupdate:
rb.AddForce(movement * speed);
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.layer == LayerMask.NameToLayer(layerMask))
{
// Get the first contact point
ContactPoint contact = collision.contacts[0];
Vector3 normal = contact.normal;
Vector3 reflected = Vector3.Reflect(rb.linearVelocity, normal);
rb.linearVelocity = reflected * 0.8f; // 0.8f = keep 80% of speed
}
}
(Please let me know if you need the full code to help out)
It works completely fine when colliding with an object with a rigidbody but when colliding with any object it just stops the ball.
I have ensured the ball I am applying forces to is set to interpolate and continuous.
The wall it is hitting has a box collider and the correct layer mask, on trigger is unchecked and nothing is kinematic.
I feel like im missing something simple here. New to unity so any help would be appreciated