Calculate velocity of a bullet ricocheting on a circle
- by SteveL
I made a picture to demostrate what I need,basecaly I have a bullet with velocity and I want it to bounce with the correct angle after it hits a circle
Solved(look the accepted answer for explain):
Vector.vector.set(bullet.vel); //->v
Vector.vector2.setDirection(pos, bullet.pos); //->n normal from center of circle to bullet
float dot=Vector.vector.dot(Vector.vector2); //->dot product
Vector.vector2.mul(dot).mul(2);
Vector.vector.sub(Vector.vector2);
Vector.vector.y=-Vector.vector.y; //->for some reason i had to invert the y
bullet.vel.set(Vector.vector);