我正在做一个2.5D游戏(想想自上而下的地牢爬虫/侧面视图,就像艾萨克的装订一样),在游戏中,角色可以向所有八个方向行走。玩家的动画工作很好,但AI动画一直在移动状态之间闪烁相当多。AI根据动画的方向移动和选择动画:
//Select which animation we should currently be in:
if (velocity != Vector2.Zero)
{
if (direction.X < 0 && direction.Y < 0 && currentAnimation.name != "Walk Up Left")
ChangeAnimation(Animations.WalkUpLeft);
else if (direction.X > 0 && direction.Y < 0 && currentAnimation.name != "Walk Up Right")
ChangeAnimation(Animations.WalkUpRight);
else if (direction.X < 0 && direction.Y > 0 && currentAnimation.name != "Walk Down Left")
ChangeAnimation(Animations.WalkDownLeft);
else if (direction.X > 0 && direction.Y > 0 && currentAnimation.name != "Walk Down Right")
ChangeAnimation(Animations.WalkDownRight);
else if (direction.X < 0 && direction.Y == 0 && currentAnimation.name != "Walk Left")
ChangeAnimation(Animations.WalkLeft);
else if (direction.X > 0 && direction.Y == 0 && currentAnimation.name != "Walk Right")
ChangeAnimation(Animations.WalkRight);
else if (direction.Y > 0 && direction.X == 0 && currentAnimation.name != "Walk Down")
ChangeAnimation(Animations.WalkDown);
else if (direction.Y < 0 && direction.X == 0 && currentAnimation.name != "Walk Up")
ChangeAnimation(Animations.WalkUp);
}
else if (velocity == Vector2.Zero)
{
if (currentAnimation.name != "Idle")
ChangeAnimation(Animations.Idle);
}问题是,有时人工智能必须对角移动,在这样做之后,他会直接向下移动几帧来纠正自己,这样他就完全在网格上了.它只适用于几个帧,所以在视觉上,它看起来非常模糊,在两个方向之间。
方向变量从来没有浮点值..。AI移动代码如下:
我使用的代码是:
private void TrimDirection()
{
//Snap our direction to one of the eight cardinal directions:
direction.X = (float)Math.Round(MathHelper.PiOver4 * (float)Math.Round(direction.X / MathHelper.PiOver4));
direction.Y = (float)Math.Round(MathHelper.PiOver4 * (float)Math.Round(direction.Y / MathHelper.PiOver4));
}移动代码如下:
if (direction.X > 0)
MoveRight();
else if (direction.X < 0)
MoveLeft();
if (direction.Y > 0)
MoveDown();
else if (direction.Y < 0)
MoveUp();我一直在努力想办法解决这个问题,我碰到了一堵墙.我是否需要实现某种类型的动画滞后,以避免动画变化如此之快?还是这个问题在我如何让AI移动的更深层次上?
提前感谢!
发布于 2013-09-23 14:43:02
好吧,如果有人有更好的主意,我是开放的,但我目前的解决办法是:
如果您等到速度到达maxSpeed时,动画更改看起来会延迟,但是如果设置的范围太低,它就不会捕捉到所有的突然变化。在我的情况下,.8f工作得很好。
到目前为止我还没有遇到任何问题..。手指保佑这招成功了!
https://stackoverflow.com/questions/18946864
复制相似问题