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 :

reflecting image

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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -