I have a character and a target where it should go. If the target is in other coordinates, then the character moves towards it, when he reach it, then the walk animation is turned off.
I have 2 problems:
When the target is moved and the character reaches it, the coordinates of the target and the character are a little different.
Target (GameObject plane) after moving has strange Y-meanings. How to make Y always equal to 0.
The screenshot shows that the character has reached the goal, but the animation does not end because their coordinates are slightly different.
Move
transform.rotation = Target.transform.rotation;
var direction = (Target.transform.position - transform.position).normalized;
_characterController.Move(direction * WalkSpeed * Time.deltaTime);
Target
if (DistanceToPlayer >= MaxDistanceToPlayer)
{
if(isMove == false)
{
isMove = true;
Vector3 NewPositionToPlayer = Player.transform.position + new Vector3 (Random.Range(-5.0f, 5.0f), 0f, Random.Range(-5.0f, 5.0f));
Target.transform.position = NewPositionToPlayer;
animator.SetBool("isWalking", true);
}
}
if (DistanceToPlayerPivot >= MaxDistanceToPlayer)
{
isMove = false;
}
if(RelativePosition == Target.position)
{
animator.SetBool("isWalking", false);
isMove = false;
}
