我有敌人使用NavMesh Agent对不同的路径点进行巡逻,我希望当敌人到达下一个方向点时,有与那个路径点相同的旋转。以下是代码:
void Update ()
{
if (agent.remainingDistance < 0.1)
{
// tried to stop the agent so I can override it's rotation, doesn't work
agent.Stop();
// Give him the desired rotation
transform.rotation = wayPoints[curretPoint].rotation;
if (curretPoint < wayPoints.Length -1)
{
curretPoint++;
}
else
{
curretPoint = 0;
}
// make him wait for a fixed amount of time
patrolTimer += Time.deltaTime;
if (patrolTimer >= patrolWait)
{
patrolTimer = 0;
agent.SetDestination (wayPoints[curretPoint].position);
agent.Resume ();
}
}
}问题是他不停地来回旋转,我不能得到我想要的效果。
发布于 2017-05-12 10:14:24
尝试将代理的角速度设置为0。
编辑:
这应该是可行的:
// make him wait for a fixed amount of time
patrolTimer += Time.deltaTime;
if (patrolTimer >= patrolWait)
{
if (curretPoint < wayPoints.Length -1)
{
curretPoint++;
}
else
{
curretPoint = 0;
}
patrolTimer = 0;
agent.SetDestination (wayPoints[curretPoint].position);
agent.Resume ();
}发布于 2017-05-12 11:59:06
这就是我处理它的方式:我没有执行agent.Stop();和agent.Resume();我只是将其速度设置为0,并使用transform.Rotate旋转字符。
https://stackoverflow.com/questions/43926950
复制相似问题