Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Given a object which may move forward, backward, left and right at a given X,Y point. How to efficiently direct the object to a X,Y point using the given movement mechanics in the most efficient and human natural way.

The object is available for movement in real time, you may tell them to "startMoving|Direction|()" and "stopMoving|Direction|()" to any heading of 360 degrees. Though as a additional twist and the part I am having trouble with, is the facing of the object is never known, only its current location is known, so the algorithm must "detect" direction. The location of the object is updated in a separate thread in 500-1second intervals. A "Request" to update the location within the algorithm made be made at any point, but it is not immediately available and the algorithm must keep that in consideration. Doing something like requestAndWaitForCoordUpdate() is perfectly acceptable, however likely not needed.

In addition, no obstacles appear, it can be assumed you are on a MOSTLY open plane, stray to far from the direct straight line between the paths and you may run into obstacles. It is safe to assume that 1/4th the distance between a target and source, should be available in width on a given direct path.

I would also mention I am not sure A* applys in this scenario, if it does I am unsure how to implement it given the constraints. The only real variable here is the facing of the object.

Here is some example code:

public int[] currentCoords;
public void movement() {
  currentCoords[0] = 1005; // starting y coord
  currentCoords[1] = 1007; // starting x coord
  moveTo(1050, 1025);
}

public void moveTo(int x, int y) {
  ... how?
}

public void threadUpdatingCoords() {
   ... periodically check for source coord updates
   ... between 200ms and 1000ms apart.
}
share|improve this question
    
What means of rotating does the object has available? –  Kasper Holdum Mar 23 '11 at 2:37
    
Not sure if I understand the question. The object may only move horizontally and vertically and cannot rotate? Is that right? –  bummzack Mar 23 '11 at 7:40
add comment

1 Answer

I suggest the first thing you do is move the object straight ahead for a short duration. Now you will know the original position as well as it's new position. From the knowledge of these you will be able to calculate the rotation of the object.

originalPosition = (3 ; 2)
newPosition = (3.5 ; 1.7)
offset = (newPosition - originalPosition) = (0.5 ; -0.3)
offsetLength = sqrt(0.5^2-0.3^2) = 0.583
currentDirection = Normalize(offset) = (0.5 / 0.583 ; -0.3 / 0.583) =(0.857 ; -0.515) 

Once the current direction is known, all you have to do is to offset the direction so it points towards the goal location and start moving until you reach it.

For additional information such as ETA you could compute the speed of object while it's moving.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.