Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
Vector.vector.normalize();
bullet.vel.set(Vector.vector);

enter image description here

share|improve this question
    
Do you need direction or velocity? If direction that is elementary school stuff... and you are already doing it in almost any shading model. –  wondra Aug 17 at 19:21
    
@wondra just the direction.Well many years have passed since elementary :) –  SteveL Aug 17 at 19:29
    
Find the slope of the circle at the point of intersection (the derivative). Use that slope/line as the line of reflection for the incoming bullet. –  Byte56 Aug 17 at 21:31
1  
Some explain for the downvotes ? –  SteveL Aug 18 at 10:11

1 Answer 1

up vote 1 down vote accepted

The formula for reflecting an incoming vector v across a unit normal n into an outgoing vector v' is

v' = v - 2*dot(v,n)*n

You can determine the normal n from normalizing the difference of the collision point and the center of the circle.

See the question on How to get a reflection vector? over on Math.SX for more elaborate derivations.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.