# Unity Change Ball Direction after hitting paddle in a Pong game (like in dx-ball)

I'm struggling with how to get the ball to change the bounce based on where it hits on the paddle. Normally in a pong game, the angle changes, depending on how far from center the ball bounces, and which direction of the center it bounces. I managed to do something like that:

//rb = rigidbody, velOnPaddleHit = predefined float
float dist = transform.position.x - paddle.position.x;
dist = transform.position.x > paddle.position.x ? dist : -dist;


But it's just not working / it's weird. Can anyone help me?

Edit: Here's the video showing this kind of behaviour. When the ball hits the left side of the paddle, it goes left, the velocity doesn't matter

• Apparently there is a mistake in your code. You supplied "-dist" explicitly, as dist in not an abs value, it will retain its + or - sign, so no need to provide -dist, otherwise -(-dist) will become +dist. Just use dist only Mar 5 '16 at 21:37
• Did you read the post? I'm checking whether the ball is on the right or on the left side of the paddle. Mar 6 '16 at 0:03
• What are you doing after finding that? Modifying dist variable by +ve or -ve, which you are not suppose to do Mar 6 '16 at 0:16

• Sorry, im an amateur, i couldn't understand a word you said :( but it seems that youre trying to tell me how to calculate the distance from the canter of the paddle to the ball, but i've done that (transform.position.x - paddle.position.x). I just need the distance on the x axis Mar 5 '16 at 18:35