Question Regarding the Reflect Angle of a Transition
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.
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.
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
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
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:
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!
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
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Formula for converting angle to vector?  komirad  2  14,188 
Jul 29, 2011 07:29 AM Last Post: ThemsAllTook 

ending location from angle and speed  Kazooless  5  6,813 
Apr 3, 2009 02:40 PM Last Post: Gillissie 

Angle between two points?  Graphic Ace  6  7,878 
Nov 8, 2008 12:11 PM Last Post: macnib 

calculating X and Y coordinates w/ an angle and distance  ferum  13  20,951 
Jun 25, 2008 10:53 PM Last Post: rosenth 

Convert vector to angle?  Leroy  35  55,153 
Jun 27, 2007 08:15 PM Last Post: unknown 