- Home /
Make Objects to ricochet
I was wondering if there is a way for objects to ricochet in the scene. I want to have some objects to move around as they collide with the wall and to keep on moving. Is there any source code to help have objects to ricochet?
Answer by Chronos-L · Apr 07, 2013 at 02:15 AM
Look at these 2 answers:
In the deflecting bullet, there is a short explanation on how one could calculate the ricochet angle/vector of a bullet. In the billiard game guide line, there is a example script regarding reflecting/bouncing the vector.
What you will do with a projectile/bullet are:
Check with colliding with a ricochet-able surface (
OnCollisionEnter
)Extract the normal of the surface you are colliding via contact point
Use the projectile/bullet's direction (
transform.forward
) and the normal to calculate the vector of the projectile/bullet when it is reflected Vector3.ReflectApply the reflected vector to your projectile/bullet