Third time I asking that question because I didn't get any answer or even comment...
In my game there is an enemy that have 4 animations: walk, aim, put the gun away and hold the gun. When the game starts - the enemy hold he's gun ("HoldGun animation". I set this part on the inspector by "Play Atomatically"). So far so good... When I get closer - the enemy should aim on me ("GoingToShoot animation"). Now the problem starts - the enemy do the aniamtion in loops, thing he shouldn'd do so he seems "dancing". When I get closer - the enemy should gut the gun away ("StopShoot animation") walk a bit to me ("R.H.Walk animation"). When he needs to do the "R.H.Walk animation" he just stop do the "GoingToShoot animation" that was in loop and go forward without do any animation. When he get to the range he needs to shoot he should do the "GoingToShoot animation" again and shoot, he don't do that - he just start "dancing" again.
I didn't set the shooting yet.
Here Is the code:
var distance;
var target : Transform;
var lookAtDistance = 70.0;
var attackRange = 60.0;
var deadRange = 50.0;
var moveSpeed = 5.0;
var damping = 4.0;
var shootTest = false;
static var ableFire = false;
function Update ()
{
distance = Vector3.Distance(target.position, transform.position);
if(distance < lookAtDistance)
{
renderer.material.color = Color.yellow;
animation.Play("GoingToShoot");
lookAt ();
}
if(distance > lookAtDistance)
{
renderer.material.color = Color.green;
}
if((distance < attackRange)&&(distance > deadRange))
{
if (shootTest == true)
{
animation.Play("StopShoot");
shootTest = false;
attack ();
}
else
{
attack ();
}
}
if(distance < deadRange)
{
stop ();
shootTest = true;
ableFire = true;
}
}
function lookAt ()
{
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
function attack ()
{
animation.Play("R.H.Walk");
ableFire = false;
renderer.material.color = Color.red;
//transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);
var offsetDirection = target.position - transform.position;
offsetDirection.y = 0;
var rotation = Quaternion.LookRotation(offsetDirection);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
transform.Translate(offsetDirection.normalized * moveSpeed *Time.deltaTime, Space.World);
}
function stop ()
{
renderer.material.color = Color.black;
}
My Question is this: Why the enemy keep "dancing" and how I can get him stop do that???
This is an enemy that I created in Blender and imported it with hes animations. I never had problems with imported animations before...
Sorry for poor english as allways... :(