Procedural animation conflicting with animation clips.

I’ve got an enemy character who walks around. I also want to add a script to turn his head to face the player. I only run this code when you are within a certain range of the enemy, otherwise I want it to continue with the regular animation for the head bone.

Rotating the head is no problem, but once it stops executing that code, the animation doesn’t take over again. The head bone remains rotated to the angle I set it to the last time the code was run. I can’t for the life of me figure out how to get the original animation to take over again.

Can you post the code you are using to override the animation? Typically, bone transform changes in LateUpdate will override animations but then the original animation will resume when the LateUpdate changes are stopped. Is it possible that the override code keeps executing and using the last rotation position even though it isn’t updated?

That was my first thought too, that the code was being executed when it shouldn’t have been, but I ruled that out by sticking some other code in the else condition to test, but I don’t know what else it could be. My code is already in LateUpdate too. The normal animation works fine until the first time the condition is triggered, then it just sticks.

Excuse the messy code. This is the only code that is touching the head transform. The rest of the code is a bit of a mess, but I don’t think it’s relevant.

function LateUpdate() {

if (enemy_alive)
{
	var head_target : Vector3 = Player_Movement.script.player_position + Vector3(0,1.5,0);

	var target_angle : float = (Mathf.Atan2(Mathf.Abs(enemy_head.position.x - head_target.x), head_target.y - enemy_head.position.y) * Mathf.Rad2Deg);


	if (Mathf.Abs(target_angle) < 15.0)
	{
		enemy_head.localEulerAngles = Vector3(0,target_angle,0);
	}
	else
	{

	}

}

}

edit never mind, I just solved it five minutes after bumping this, so I’ll just clear this.

Just for future reference, the only reason the original animation wasn’t taking over was that because I forgot to add any animation keys for the head animation, so the animation had no keyframes to take over. I usually add keyframes for non moving limbs anyway, and assumed my export options would take care of it anyway, but apparently not. So there you go. :slight_smile: