- Home /
Question by
General-Troll · Mar 02, 2015 at 03:08 AM ·
animationaifreezeframe
All AI animations stop on first frame
So, I'm experiencing a big problem with my game. I have about 4 animations assigned to my soldier enemy (Standing[idle], StandingAim[lookat], StandingFire[attack], RunAim[chase]). Every time I get the soldiers to play an animation other than Standing, the enemy will do what it is supposed to, but the animations will only play the first frame. Code: var Distance; var Target : Transform; var lookAtDistance = 25.0; var chaseRange = 15.0; var attackRange = 4; var moveSpeed = 5.0; var Damping = 6.0; var attackRepeatTime = .32; var Effect : Transform; var TheDammage = 40; var shooting = false; var Enemy : Transform; private var attackTime : float;
var controller : CharacterController;
var gravity : float = 20.0;
private var MoveDirection : Vector3 = Vector3.zero;
function Start ()
{
attackTime = Time.time;
Enemy.animation.wrapMode = WrapMode.Loop;
}
function Update ()
{
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < lookAtDistance)
{
lookAt();
}
if (Distance > lookAtDistance)
{
Enemy.animation.Play("Standing");
}
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);
Enemy.animation.Play("StandingAim");
}
function chase ()
{
Enemy.animation.Play("RunAim");
moveDirection = transform.forward;
moveDirection *= moveSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function attack () : IEnumerator
{
var hit : RaycastHit;
var fwd = transform.TransformDirection (Vector3.forward);
if (Time.time > attackTime)
{
if(shooting == false) {
if (Physics.Raycast (transform.position, fwd, 10)) {
Enemy.animation.Play("StandingFire");
shooting = true;
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
Target.SendMessage("ApplyDammage", TheDammage);
yield WaitForSeconds (attackRepeatTime);
shooting = false;
}
}
}
}
function ApplyDammage ()
{
chaseRange += 30;
moveSpeed += 2;
lookAtDistance += 40;
}
Comment