Question Regarding the Reflect Angle of a Transition

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... Blush

Thanks a lot.
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
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 Cry
Quote this message in a reply
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:

horizontalDistance = ballCenterPosition.x - paddleCenterPosition.x

newBallVelocity.x = horizontalDistance * some coefficient (play with it)
newBallVelocity.y = -oldBallVelocity.y


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
"It is better to be The Man than to work for The Man." - Alexander Seropian
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Formula for converting angle to vector? komirad 2 10,061 Jul 29, 2011 07:29 AM
Last Post: ThemsAllTook
  ending location from angle and speed Kazooless 5 4,555 Apr 3, 2009 02:40 PM
Last Post: Gillissie
  Angle between two points? Graphic Ace 6 5,483 Nov 8, 2008 12:11 PM
Last Post: macnib
  calculating X and Y coordinates w/ an angle and distance ferum 13 15,130 Jun 25, 2008 10:53 PM
Last Post: rosenth
  Convert vector to angle? Leroy 35 30,887 Jun 27, 2007 08:15 PM
Last Post: unknown