Make pivot transition in mecanim in a 2.5d game?
So i have a 2.5d game, and i want to trigger a pivot animation in my animation tree when i want to change directions quickly while running, i dont know what would be the best way to do it, i tried the transition on a bool variable and on a trigger, but both become glitchy when i press the left and arrow keys quickly. Any ideas?
Here is my animation tree, ignore all the jumping leaping and pushing (quite messy i know)
From my running 40 (running to the right animation) i have a transition to turn with the condition of is pivoting (bool) and then i have the transition back to running flipped with no exit time nor conditions
here is in video https://www.youtube.com/watch?v=wnjyVJ1pfTs&feature=youtu.be in the later part of the video the character keeps turning on its own
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class drive : MonoBehaviour
{
public Animator anim;
public float translation;
public Rigidbody rb;
//TIME SINCE RUNNING TO THE RIGHT
float timerSinceRunningRight = 0.0f;
float secondsSinceRunningRight;
//TIME SINCE RUNNING TO THE LEFT
float timerSinceRunningLeft = 0.0f;
float secondsSinceRunningLeft;
// Update is called once per frame
void Update()
{
timerSinceRunningRight += Time.deltaTime;
secondsSinceRunningRight = (timerSinceRunningRight % 60);
//print(secondsSinceRunningRight+" seconds since running Right");
timerSinceRunningLeft += Time.deltaTime;
secondsSinceRunningLeft = (timerSinceRunningLeft % 60);
//print(secondsSinceRunningLeft+" seconds since running Left");
translation = Input.GetAxis("Horizontal") * speed;
translation = translation * Time.deltaTime;
if (translation > 0 && secondsSinceRunningLeft < 0.5f)
{
timerSinceRunningRight = 0f;
Pivot();
isRunningRight();
Debug.Log("is Pivoting");
}
else if (translation > 0)
{
timerSinceRunningRight = 0f;
isRunningRight();
}
else if (translation < 0 && secondsSinceRunningRight < 0.5f)
{
timerSinceRunningLeft = 0f;
Pivot();
isRunningLeft();
Debug.Log("is Pivoting");
}
else if (translation < 0)
{
timerSinceRunningLeft = 0f;
isRunningLeft();
}
else
{
idle();
}
}
void isRunningRight()
{
anim.SetBool("isWalking", true);
anim.SetBool("isWalkingFlipped", false);
}
void isRunningLeft()
{
anim.SetBool("isWalkingFlipped", true);
anim.SetBool("isWalking", false);
}
void idle()
{
anim.SetBool("isWalkingFlipped", false);
anim.SetBool("isWalking", false);
}
void Pivot()
{
{
anim.SetBool("isPivoting",true);
}
}
}