NavMesh Agent의 회전값이 너무 느릴 때 ( Unity NavMeshAgent Angular speed )

https://answers.unity.com/questions/660646/increase-navmesh-rotation-speed.html

 

의도한건지는 모르겠지만, 

NavMesh Agent는 회전값을 아무리 올려도 너무 느리게 움직이는 단점이 있다.

 

 

# 방법 1

다음과 같이 update문에서 회전 값을 계속 업데이트해주면 회전속도가 정상적인 수준으로 증가한다.

float extraRotationSpeed = 5f;

void Update()
{             
    Vector3 lookrotation = agent.steeringTarget-transform.position;
    transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(lookrotation), extraRotationSpeed*Time.deltaTime); 
}

 

# 방법 2

이재현 마스터의 내비게이션 활용법
https://www.youtube.com/watch?v=RmDRjoXUaTI

NavMesh에서 회전처리를 하지못하도록 아예 끌 수도 있다!

    void Awake()
    {
        navMeshAgent = GetComponent<NavMeshAgent>();
        navMeshAgent.updateRotation = false;
    }

 

# 순간적인 회전의 경우

순간적인 회전의 경우 다음과 같이 navMesh를 끄고, 회전시키고 (LookAt이 아니라 Rotation을 변경해도된다.)

NavMesh를 다시켜면된다. 굳이 Invoke 등이나 Coroutine없이 같은 프레임내에서 행해도 된다.

NavMeshAgent.enabled = false;
transform.LookAt(curTarget);
NavMeshAgent.enabled = true;

 

 

 

댓글

Designed by JB FACTORY