Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 13 Mar 2013
Offline Last Active Apr 11 2013 03:04 AM

Topics I've Started

Circular Playing Field

14 March 2013 - 05:19 AM

Hi all,
I am currently making a 2D shooting game, but have gotten stuck trying to solve this one problem.
I have a circular playing field, which is the area the player (or other entities) is allowed to move around in. However, I have tried all the method I could think of, and searched the forums here in an attempt to find anything useful, but did not. I have no problem with detecting when the player is on the boundary, but restricting the player within it is the problem for me..
What I wish to achieve is that the player will hit the wall and, if it is not on any of the eight cardinal or ordinal "corners" of the circle, slide towards it. So, for example, if the user held down [up] and [left], the player would move northwest until it hits the wall, then continue to slide along till it is at the northwest position on the circle.
Illustration of my point (I hope it is clear enough):
As can be seen, my idea was to calculate an opposing force r. So, in this example, ry cancels out the player's y velocity, but the player continues to move leftwards. So as the player moves towards northwest, rx grows larger and eventually cancels out the player's x velocity too making that the final resting position.
I am not sure if there is any flaw in this approach itself, or that my method of computing rx and ry were wrong. Here is my most recent try:

My maths isn't that good, so I am really out of ideas. If someone could give me any help it would be greatly appreciated! Thanks.