开发者

C# Pathing algorithm for moving a object from point(X, Y) to point(X, Y)

开发者 https://www.devze.com 2023-02-18 16:22 出处:网络
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 h

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" and "stopMoving". 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 sep开发者_开发问答arate 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.

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.
}


If I understand this correctly, you need to determine your direction.

Also, you can query your current position.

Can you store your last coordinates before going to a new position?

If so, use basic Trigonometry to extract the angle your object is moving in based on the last coordinate and the new coordinate.

0

精彩评论

暂无评论...
验证码 换一张
取 消