I want to create a click-to-move game, and have got a nav-mesh agent with code which almost works, except my character always attempts to move to the same spot, regardless of where I click or the position of the camera. This is my function,
private Vector3 GetClickPosition()
{
Vector2 screenPosition = Input.mousePosition;
Vector3 mouseWorldPosition = cam.ScreenToWorldPoint(screenPosition);
RaycastHit hitPosition;
Physics.Raycast(mouseWorldPosition, cam.transform.forward, out
hitPosition, 100, Floor);
return hitPosition.point;
}
Which is used in an on-click command connecting to the player. Everything is referenced and I'm sure the problem is with this piece of code... Thanks in advance.
My source for this code: https://www.youtube.com/watch?v=LoKNYlWWeSM