I have a model of a wolf in game that is “supposed to” face the character when he comes within a certain distance, and then chase him as he gets closer. Unfortunately the model seems to face away from the character upon entering said zone. Is there anyway to adjust this through the script?
var Distance;
var Target : Transform;
var lookAtDistance = 25.0;
var chaseRange = 15.0;
var attackRange = 1.5;
var moveSpeed = 5.0;
var Damping = 6.0;
var attackRepeatTime = 1;
var theDammage = 10;
private var attackTime : float;
var controller : CharacterController;
var gravity : float = 20;
private var moveDirection : Vector3 = Vector3.zero;
function Start(){
anim = GetComponent("Animator");
attackTime = Time.time;
}
function Update (){
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < lookAtDistance){
lookAt();
}
if (Distance > lookAtDistance){
}
if (Distance < attackRange){
attack();
}
else if (Distance < chaseRange){
chase();
}
}
function lookAt (){
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}
function chase (){
moveDirection = transform.forward;
moveDirection *= moveSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function attack(){
if (Time.time > attackTime)
Target.SendMessage("ApplyDammage", theDammage, SendMessageOptions.DontRequireReceiver);
attackTime = Time.time + attackRepeatTime;
}
}
function ApplyDamage (){
chaseRange += 30;
moveSpeed += 2;
lookAtDistance += 40;
}