## Question Regarding the Reflect Angle of a Transition

Nibbie
Posts: 2
Joined: 2010.04
Post: #1
Hi, I'm new to iPhone game development and I plan to start developing a simple pong game.

I am currently using CGRectIntersectsRect for my collision detection and reflecting the ball after it hits the bat by simply reversing the angle where it hits the bat.

What I am trying to do is to make it so that the reflect angle of the ball is determined by the position of where it hits the bat, and not a simple reversing of direction. (E.g. if the ball lands in the middle of the bat, it will go straight, the further away from the middle, the bigger the reflect angle)

Can someone enlighten me on this particular problem I am having?

I hope my question is understandable...

Thanks a lot.
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Nibbie
Posts: 2
Joined: 2010.04
Post: #3
Umm... I've read the link you've posted, it's the mathematical equation of converting a normal coordinate into polar coordinate, but I don't have any idea how to relate it to the reflect angle of the ball when it hits the bat...

Can you guide me on how to implement the mathematical equation to the programming itself?

I tried googling on this particular topic and everyone gives a different idea on how to do it, I am so confused...

Sorry but I'm still new in this, please go easy on me
Member
Posts: 338
Joined: 2004.07
Post: #4
For this math, I'm assuming your paddle is horizontal, and your ball has hit it from the top. (Using breakout as a model here since that's the exact behavior you want.)

The pseudocode in a nutshell:

Code:
```horizontalDistance = ballCenterPosition.x - paddleCenterPosition.x newBallVelocity.x = horizontalDistance * some coefficient (play with it) newBallVelocity.y = -oldBallVelocity.y alternatively, newBallVelocity.x = oldBallVelocity.x + horizontalDistance * some coefficient (play with it)```

Note I'm using velocity as a vector here with x and y components instead of an angle in degrees/radians-- it's much easier to visualize it this way for me. Hope that helps!

Justin Ficarrotta
http://www.justinfic.com
"It is better to be The Man than to work for The Man." - Alexander Seropian