So like I been having this problem for awhile and I’m honestly not sure if it’s the code or the Animator that I have set up wrong. So my problem is that I have sort of two idle animations. One is the main default animation that it starts with and then I wanted to have when you target an enemy, it switches to an attack mode idle mode. Probably is that even with or without an exit time, the animations overlap each other and it still tries and goes back to the main idle even though the transition set up shouldn’t allow it.
I’m really scratching my head cause if I can’t get this to work, I won’t be able to set up other animations correctly either.
Code is Below (please ignore the fragments of legacy code, it is a WIP upgrading code lol):
#pragma strict
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
var animator : Animator;
var target: Transform;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
animator = GetComponent(Animator);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Directional Movement with Arrow Keys and WASD
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.W) ||
Input.GetKey(KeyCode.S)) {
animator.SetFloat("arrowKey", 1.0);
animator.Play("note_walk01");
}
else {
animator.SetFloat("arrowKey", 0.0);
animator.Play("note_idel01");
}
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) {
//animator.Play("note_idel01");
transform.Rotate(0, -1, 0);}
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)){
//animator.Play("note_idel01");
transform.Rotate(0, 1, 0);}
// Attack animations to be triggered when attacking
if (Input.GetKeyDown(KeyCode.Tab)){
target = GameObject.FindWithTag("Enemy").transform;
animator.SetBool("foundEnemy", true);
}
if (Input.GetKey(KeyCode.F)) {
animator.SetFloat("attackButton", 1.0);
}
else {
animator.SetFloat("attackButton", 0.0);
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
And my animation tree that I have currrently up and running… kinda