- Home /
Enemy AI and Rigid Bodies
Hi I am creating a game for fun and I have a script to move the enemies toward the player. However they seem to just float/hover toward the player. I tried adding a rigid body to give the enemies gravity and keep them on the ground, but it did nothing. I also added the character controller but that didn't do anything either. Please let me know what I am doing wrong. Here is the script:
var target : Transform; var moveSpeed = 3; var rotationSpeed = 3;
var myTransform : Transform;
function Awake() {
myTransform = transform;
}
function Start() { target = GameObject.FindWithTag("Player").transform;
}
function Update () {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
I have done a video series on this : http://www.youtube.com/watch?v=p9yLZmgkFWY
and please format your code : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers
Your answer
Follow this Question
Related Questions
Rigid body enemy 1 Answer
Enemy AI problems 2 Answers
A question about AI 0 Answers
Is the Player Being Looked at 1 Answer
EnemyAI C# Error 1 Answer