I have an AI Zombie Character who should follow me.
When he just sees me, he goes to another position( probably my Spawnpoint). So the rotation to my main character is also bugging.
I use rigidbody and it makes so many bugs, i just cant understand it.
Here is the part of my script :
protected void RotateTo(Vector3 targetPosition)
{
Quaternion destRotation;
Vector3 relativePos;
relativePos = targetPosition-transform.position;
Vector3 tap;
Vector3 trp;
tap = targetPosition;
trp= transform.position;
tap.y=0;
trp.y=0;
relativePos = tap-trp;
destRotation=Quaternion.LookRotation(relativePos);
transform.rotation = Quaternion.Slerp(transform.rotation,destRotation,speedRotation*Time.deltaTime);
}
protected void Walk(Vector3 targetPosition){
Vector3 moveDirection = transform.TransformDirection(Vector3.forward);
Vector3 velocity;
Vector3 delta = targetPosition-transform.position;
if(delta.magnitude>minimalDistance){
velocity = moveDirection.normalized * movingSpeed*Time.deltaTime;
// animation.CrossFade("run");
characterAnimationState = AnimateState.run;
}
else {
velocity = Vector3.zero;
// animation.CrossFade("idle");
characterAnimationState = AnimateState.idle;
}
rigidbody.velocity = velocity;
}
Help would be pretty nice :), it should be a little problem.