With this script, the char. patrols way points as default, when he reaches an animation plays. I been trying to add the function that if you press a key it will allow you to control him with your mouse (such as a target). My issue is, if I press the button while he is walking, it seems to work. But if the char is stopped at a waypoint and an animation is playing, the char wont break free allowing to be controled with a mouse. Please ask for the full script if you think it will help.
void Update ()
{
if (Input.GetButton ("FreeWalk"))
FreeWalk ();
else if (isClicked) {
Running ();
}
else if (enemySight.playerInSight) {
if (!isClicked)
Running ();
} else if (enemySight.personalLastSighting != lastPlayerSighting.resetPosition) {
Chasing ();
} else {
if (!isClicked)
Patrolling ();
}
}
void FreeWalk ()
{
if (target != null) {
// update the progress if the character has made it to the previous target
if ((target.position - targetPos).magnitude > targetChangeTolerance) {
targetPos = target.position;
nav.SetDestination (targetPos);
}
// update the agents posiiton
nav.transform.position = transform.position;
// use the values to move the character
character.Move (nav.desiredVelocity, false, false, targetPos);
} else {
// We still need to call the character's move function, but we send zeroed input as the move param.
character.Move (Vector3.zero, false, false, transform.position + transform.forward * 100);
}
}
public void SetTarget(Transform target)
{
this.target = target;
}