javascript - how can i find the angle of a reflecting line? -
i trying make game pong ( math bad , working on it) , trying bouncing ball part.
i trying calculate out going(reflecting) angel of ball after hitting walls or pedals (the walls horizontal , pedals vertical)
here image demonstrate better :
here tried far:
var m = (y2-y)/(x2-x); var angle = (math.atan(-m)*57.2957795);
how ever not seem work.
since obstacles vertical or horizontal, not need angle calculations. if store ball's position (x, y) , it's velocity (vx, vy) can @ each frame compute next position (x + vx, y + vy)
to bounce horizontal border, negate vy, bounce vertical borders negate vx.
Comments
Post a Comment