Well I’ve been making my first unity game, and I’ve encountered this issue where in game objects, like capsules, will follow the correct AI in the script, however.
My imported model from blender does not follow it properly, it works fully, except the part where it’s actually supposed to follow me around, seen here in my update video: RPG Game Update #03 - YouTube (Starts at the point of the issue)
(I tried adding that controller line into the start function, no difference at all)
Screenshot: http://img811.imageshack.us/img811/1608/screenshot20130520at928.png
My code looks like this
var Distance;
var Target : Transform;
var lookAtDistance = 25.0;
var chaseRange = 15.0;
var attackRange = 1.5;
var moveSpeed = 3.0;
var Damping = 6.0;
var controller : CharacterController;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
var attackRepeatTime = 1;
var TheDamage = 20;
private var attackTime : float;
function Start()
{
attackTime = Time.time;
}
function Update ()
{
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < lookAtDistance)
{
lookAt();
}
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("ApplyDamage", TheDamage);
Debug.Log("Enemy has attacked");
attackTime = Time.time + attackRepeatTime;
}
}
function applyDamage ()
{
chaseRange += 30;
moveSpeed += 2;
lookAtDistance +=40;
}
Please help me, this is really halting my progress! D: