Ok, So i am using an AI script in my game and i need a little help understanding a few of the components of the scrip. I am following a video tutorial series and i am trying to understand more about what the script means and how it works with the objects in game. (basically i did what the man in the tutorial did and i need some help understanding what is going on)
First off, what is the characterController variable doing? The AI object is supposed to move towards me and even when i am in range of it, it just does move at all! When in unity under the property inspector the script has an option to add some sort of controller to the character controller spot, but when i do that i can go within the lookatdistance. (see code below to answer)
If you know any other reason why it is not chasing me, please help it would be much appreciated.
var Distance;
var Target : Transform;
var lookAtDistance = 25.0;
var attackRange = 15.0;
var moveSpeed = 5.0;
var Damping = 6.0;
function Update ()
{
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < lookAtDistance)
{
renderer.material.color = Color.yellow;
lookAt();
}
if (Distance > lookAtDistance)
{
renderer.material.color = Color.green;
}
if (Distance < attackRange)
{
renderer.material.color = Color.red;
attack ();
}
}
function lookAt ()
{
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}
function attack ()
{
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
↧