Hi im new to game making and know 0 coding but "Understand" bits and pieces. I am attempting to make a chasing AI that always follows the player but when I turn a corner or in this case a hall with a few openings I turn the corner and it seems to follow me in a strait line instead of following as it should.
The code im using:
var target : Transform;
var moveSpeed = 3;
var rotationSpeed = 3;
var myTransform : Transform; //current transform data of this enemy
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}
function Start()
{
target = GameObject.FindWithTag("Player").transform; //target the player
}
function Update () {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
Screen shots for example:
http://i.imgur.com/Gy72iaU.png
http://prntscr.com/6qidv9
↧