Hello,
I am working on bouncing projectiles. I know it is easy to have the physics make them bounce and I currently have them bouncing that way.
The problem is I need to predict where they are going. When I cast rays out and have them reflect off walls the path the projectile follows is different than the path the rays go. I believe that the physics engine must not do pure reflection, maybe because of some sort of mass, drag, or something.
I am trying to handle bouncing the projectiles myself, but they seem to just move along the wall and not bounce.
So if someone can help me, what I need is:
1: how does the physics get the bounce angles so I can emulate it?
2: how do I get the projectile to go the direction I want?
The answer to one of these two questions would be appreciated,
-Taylor
PS. Here is some code:
function OnCollisionEnter(collision : Collision)
{
var contact : ContactPoint;
if(numBounces > 0 (collision.gameObject.layer != 8))
{
contact = collision.contacts[0];
var dot : float = Vector3.Dot(contact.normal, (-transform.forward));
dot *= 2;
reflection = contact.normal * dot;
reflection = reflection + transform.forward;
rigidbody.velocity = rigidbody.TransformDirection(reflection.normalized * 15.0);
numBounces -= 1;
}
else// the else doesn't matter
I typed the code, not copy and paste, so small errors are not the problem, its the math or how I am using it.