I am working on writing a pong game, and I ran into a problem.
I am trying to figure out how to bounce a point from a line.
The best way I can do this is
- Calculate the current and future position of the ball.
- Line segment: {Ball.location, Ball.location + Ball.direction} (Ball.location and Ball.direction use a custom vector / coordinate class)
- Calculate if the generated line segment intersects with any of the walls or blades.
- ??? I don’t know how to do this (ask in a separate question)
- At the first intersection found
- Kick the ball off the line
- Create a triangle formed with
- a = Current step position
- b = The point of intersection of the line.
- c = The closest point to the current position of the ball on the line.
- Find the angle at which the ball hits the line
- angle = cos ( (b, c)/ (a, b))
- ?