我正在开发一个等距游戏(菱形网格),我偶然发现了一个关于角色移动的小问题。
我正在使用 A* 找到 2 点之间的路径,然后我想将我的角色从 A 点移动到 B 点,穿过形成路径的所有图块,但我找不到这样做的方法,我的意思是一种更简单、更准确的方法。
到目前为止,我已经废弃了这段代码,但它有点“生锈”
public void Destination(tile destination)
{
for (int i = 0; i < 8; i++)
{
if (AdjacentTile[i] == destination)
{
characterDirection = i;
}
}
animation.changeSpriteDirection(characterDirection); //After I found which adjacent tile is the next destination I change the character direction based on it's position (1 = North , 2 = Nort Est etc) .. so the Y of the Animation_sourceRectangle it's changed//
Vector2 Position;
Position.X = current_characterTile.X - destination.X;
Position.Y = current_characterTile.Y - destination.Y;
rotation = (float)Math.Atan2(-Position.X, Position.Y);
moveVector = (Vector2.Transform(new Vector2(0, -1), Matrix.CreateRotationZ(rotation))) * characterSpeed;
movingCommand = 1; // the character is supposed to be moving..
Move(); //this function moves the sprite until the *tile.i and tile.j* of the character is the same as tile.j and tile.i of the destination
//something like this
if ( characterTile.i == destination.i && characterTile.j == destination.j)
movingCommand = 0 //stop
else
character_Position += moveVector;
}
如果有人能给我提示或帮助我,我将不胜感激。
谢谢你。