Well I have run out of ideas how to approach this particular problem.See the picture below:

enter image description here

So the idea is that the object (dot in black) has to get to a point mark X (red X mark).However the limitation is that it has to get there without crossing the circle (i.e going in the straight line the the X mark).I was reading on some steering algorithsm but seems rather too complicated for this problem.Also I should mention that the object has the speed and velocity and position attributes which controls how its moving.

Now I was reading some ideas on how to move an object around a circumference here:


However this doesn't entirely answer my question.The thing is I first need to get to the circle in order to be able to move around it.What I was thinking,was to allow the object to move towards the position in a straight line until it hits the circle and then start moving along the circumference of the circle.Also the "X" mark can be anywhere on the circle even right in-front of it (not behind on the other side of the as in this example shown in the image)

I am not a game developer and thus never came across issues like so.The idea is that there will be more than one black object trying to get to their own "X" mark on the circle from random positions.(They idea is that they will be surrounding some objects in the middle). Here is an image to show what I mean,where each black object has an X position that they need to attend to without directly going through the circle.(Sorry for my bad drawings,was using laptop track-pad to do these images) enter image description here

Anyway I am kinda lost with this and would to see different on tackling this particular problem.

  • \$\begingroup\$ Can we assume you know the coordinates for the center of the blue circle and its radius and the coordinates of all the black dot's starting positions? Also, how do you store the X's location? By angle around circle (where's 0 then?) or by coordinates? \$\endgroup\$ – Steve H Feb 1 '13 at 2:50
  • \$\begingroup\$ I have the co-ordinates for the centre of (x,y) and the radius of it.I am also X location is stored in terms of x,y co-ordinates but I also have the angle that its located on.Each black dot (object) is also stored as x,y co-ordinates with a width attribute so I can get its radius from that too. \$\endgroup\$ – Tohmas Feb 1 '13 at 12:38

I can think of a couple ways to approach this problem.

hand-drawn diagrams

(Figure 1) Find the closer tangent point to aim towards, then steer along the edge of the circle. This should be the path with the shortest distance.

(Figure 2) In polar coordinates, plot a path that interpolates the angle Θ and radius r from the starting point to the desired point. These points are not equidistant, so use them as intermediate waypoints for travel. Since rpoint never goes below rcircle, you are guaranteed it will not cross the circle boundary.

  • \$\begingroup\$ So as I understand for figure two what you are doing is getting the distance from the middle of the circle to the object and using it as the radius which is then decreased as the object moves along the decreasing radius while proportionally decreasing the angle.I am not strong on the mathematical side of these things as I never developed any games before. \$\endgroup\$ – Tohmas Feb 1 '13 at 14:48
  • \$\begingroup\$ @Tohmas Yes. that is exactly what I meant in Fig 2. \$\endgroup\$ – Jimmy Feb 1 '13 at 18:00
  • \$\begingroup\$ Thanks for the ideas Jimmy,I will have a go at implementing the second idea tomorow. \$\endgroup\$ – Tohmas Feb 2 '13 at 0:00

It sounds like your desired motion consists of two stages: first move directly toward the target point (x) until you hit the circle; then, move around the circle to the target point, if necessary.

Since there are two stages, you could use a state machine with two states indicating which kind of motion you're currently doing.

In the first state, just set the velocity using the vector from the object to the target point, scaled to the desired speed.

You can detect if you're about to run into the circle by checking whether the next frame position (after physics updates) would be inside the circle. If that occurs, adjust it so you don't enter the circle - this could be done by simply clamping to the nearest point on the circle, or by doing a ray-circle intersection test to find the exact point of contact (but you may not need to be that accurate). In any case, once you've hit the circle, switch to the second state.

Then apply the answers to the question you linked to to move around the circle to the target point.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.