Calculate velocity of a bullet ricocheting on a circle
Posted
by
SteveL
on Game Development
See other posts from Game Development
or by SteveL
Published on 2014-08-17T19:18:59Z
Indexed on
2014/08/18
16:48 UTC
Read the original article
Hit count: 284
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);
© Game Development or respective owner