So I’m having a problem with my Click-to-Move and NavMesh.
When I click on a game object with a collider my character will move their with no issue. The issue comes from when I click on an area not covered by my NavMesh and my character walks on the edge of the NavMesh trying to reach that point until I select a new location he can actually reach.
Is there a way to get my character to stop on the edge of the NavMesh or to make my NavMesh the target for my raycast so I can remove all the colliders from my level map?
Feel free to answer in C#.
var targetPosition : Vector3;
private var agent : NavMeshAgent;
function Start()
{
agent = GetComponent(NavMashAgent);
targetPosition = transform.position;
}
function Update()
{
if (Input.GetMouseButton(0))
{
setPosition();
agent.SetDesination(targetPosition);
}
}
function setPosition()
{
var mousePosition : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast(mousePosition, hit, 1000))
{
targetPosition = hit.point;
}
}