Getting the direction in javascript

Hello! Im trying to make a javascript pong game but when the ball(aka a square) hits one of the pong sticks, I don’t know which direction to make it go in. For example, if a ball bounces off the floor and it comes in(to the floor) at a 45° angle, then it would come out at a 135° angle(i think) but I don’t know how to get its actual direction. If you don’t want to look at the code, I have collision, the ball’s x, the ball’s y, the ball’s x and y speed, and all that other stuff.
Code is at https://github.com/HenryHell0/Pong-The-Game

If you know what side the ball is hitting something, then all you need to do is negate the x or y that relates that side. For contact with the top or bottom of things, negate the y. For contact with the left or right of things, negate the x. (This assuming we’re not bouncing off of round or irregularly shaped things).

1 Like