Ok, i’m studing about the NavMesh componets implementing a game where the Camera always follow the player from behind. My problem is i want to move my player forward acording to my gameObject.transform.forward:
Vector3 targetPosition = new Vector3 (horizontalImput, 0f, verticalImput);
and send it to the NavMeshAgent handle the movimentation:
navMeshAgent.Move (targetPosition * speed * Time.deltaTime);
the NavMeshAgent move my gameObject correctly if his transform.foward is the same as the global Y axis but my object rotate (45º for example) how to i handle it?
Well, after a while doing other suff i manage to get a solution!
// Create a target position according to input and lookingPosition.
Vector3 verticalMovimentation = transform.forward * verticalImput;
Vector3 horizontalMovimentation = transform.right * horizontalImput;
float slerpTValue = Mathf.Abs(verticalImput / horizontalImput)/2;
Vector3 targetPosition = Vector3.Slerp(horizontalMovimentation, verticalMovimentation, slerpTValue);
targetPosition.y = 0.0f;
// Move player
navMeshAgent.Move(targetPosition * speed * Time.deltaTime);
not sure if it is the best way of doing it but fit as glove to me.