# How can the resultant velocity of an object after a potential collision be predicted?

I’m creating a game with a mechanic similar to Peggle. I’m launching a small spherical projectile at a capsule. The rigidbodies of the objects are constrained such that the collision is effectively 2D (just two circles colliding). I want to calculate the direction the projectile will be heading after the collision.

Currently this is my process:

1. Call `Physics.SphereCast` along the path of the projectile.
2. Reflect the projectile velocity about the `RaycastHit.normal` vector.
3. Place an arrow object at `RaycastHit.point` facing the direction of the reflection vector.

Here’s the relevant code (the projectile is launched from the origin):

``````var raycastHit:RaycastHit;
if(Physics.SphereCast(Vector3.zero, radius, projectileDirection, raycastHit, range)) {
arrow.position = raycastHit.point;
arrow.LookAt(raycastHit.point + Vector3.Reflect(projectileDirection, raycastHit.normal), Vector3.up);
}
``````

With this method, I’m having two problems:

1. The arrow direction is not accurate (as much as 15 degrees off).
2. `Physics.SphereCast` detects collisions that the actual projectile never hits (the radius of the sphere collider and the radius parameter passed to `SphereCast` are the same).

I have a hunch that this means the actual physics calculation is done differently than I am doing it here (which is the typical “reflect the velocity vector around the contact normal” model). What I need to know is: how can I more accurately predict what the result of the collision is going to be, preferably without writing physics code myself?

I’m not sure, but I suspect the raycasthit.normal is the normal of the triangle hit, not the normal at the collider’s surface - it could explain the inaccuracy. Since things are limited to a plane, I think it’s better to calculate yourself the direction: create a line equation for the vector projectileDirection and a circle equation for the cylinder, then replace x and y in the circle equation and find the intersection points - it’s a quadratic equation, so you usually ends with two points; the nearest one is the contact point. With the contact point, calculate a line from this point to the center of the cylinder - that’s the normal line - and reflects the vector projectileDirection along this normal… A piece of cake, no? Don’t panic! You can find the equations in:

http://mathforum.org/library/drmath/view/55134.html

If you need some additional help on this, let me know and I’ll try to help you.