Advertisement Jump to content
Sign in to follow this  

Find angle to get from point A to B with x amount of bounces

This topic is 855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to find the angle/direction to get from point A to B in a (rectangular) field. It is possible to bounce the ball on the sides of the field. I would like to find out what the correct starting angle would be to get it from the starting point to the end point with an x amount of bounces. 


Quite simply, im trying to derive an algorithm that allows me to put in the start and end positions (as vec2's, since its a 2D scenario) as well as the amount of bounces i would like to use to get from point A to B, the output should be the angle/direction i would have to use to execute this. Additionally it should be possible to test this in both directions (first shooting left or right from the starting point).


If anyone has any suggestions on how to do this, i'd be happy to hear it.

Edited by Louwin

Share this post

Link to post
Share on other sites

You could shoot in 4 directions, not just 2.


Before morning caffeine, I believe you can do something like this...


In the selected direction, calculate the "effective" end point, as if this were just a huge box, with no bounces.

Basically, add get the distance to the border in your selected direction, multiply it by the amount of bounces, and add that to your endpoint.

Then just get the angle between the start point and that "effective" end point.


EDIT: You might have to add a different distance on odd/even bounces -- (absolute) distance to border in selected direction for odd bounces, (absolute) distance to border in opposite direction for even bounces.

So 5 bounces gives you an effective end point that is offset by (3*absolute_distance_to_border_in_selected_direction + 2*absolute_distance_to_border_in_opposite_direction).

EDIT 2: The previous edit wasn't quite correct -- which you can see in Nanoha's image below, but I think you're able to get a rough understanding of what you need to change in order for it to work :)

Edited by Lactose!

Share this post

Link to post
Share on other sites

What a great problem to have. This solution is also along the lines of what Lactose suggests. See the attached image.


Very little maths involved with this, all you do is get those extra end points off the sides, you can see that every other the end point is mirrored (as Lactose says, flipping odd an even bounces). Once you have those points you just aim at them instead. If you want no bounces then aim directly, if you want one then aim at the second point, want 5? Aim at the 6th point and so on. It will also work firing in the opposite direction.



One potential problem is that in my image these are points but with a circle it will behave differently.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!