Hi, i’m having a animation/scripting trouble. i did all the codes fine but there is one thing that i discovered but still can’t solve. Here goes:
when i quickly press different button arrows in a short time, the animations do not respond correctly. I guess the reason is due the command Input.Getaxis(“Vertical”) and (“Horizontal”) are float values that go between -1 to 1.
Example: i’m holding left arrow and quickly press down, the animation changes to down animation but returns to left position animation.
Here is the only reason i could imagine, The values are still going to 0, then the animation with the respective value at moment different of 0 triggers again and somehow get stucked in walking animation not returning to the last command animation or static animation.
If i am totally wrong about everything is fine, but please give me a solution.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public GameObject player;
public Animator animate;
public float speed=0.025f;
public bool walkleft = false;
public bool keepsideleft = false;
public bool front = false;
public bool back = false;
public bool keepsideright = false;
public bool walkright = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float h = Input.GetAxis(“Horizontal”);
float v = Input.GetAxis(“Vertical”);
if (h>0 && h<0.10)
{
Debug.Log(“Right”);
keepsideright = true;
keepsideleft = false;
walkleft = false;
walkright = false;
backfront = false;
}
if (h>= 0.10 && h<=1)
{
walkright = true;
keepsideright = false;
keepsideleft = false;
walkleft = false;
backfront = false;
player.transform.Translate(h*speed, 0, 0);
}
if (h<0 && h> -0.10)
{
Debug.Log(“Left”);
keepsideleft = true;
keepsideright = false;
walkleft = false;
walkright = false;
back = false;
front = false;
}
if (h<= -0.10 && h>=-1)
{
walkleft = true;
keepsideright = false;
keepsideleft = false;
walkright = false;
back = false;
front = false;
player.transform.Translate(h*speed, 0, 0);
}
if (v < 0)
{
Debug.Log(“front”);
front = true;
keepsideright = false;
keepside = false;
walk = false;
walkright = false;
back = false;
speed = 0;
}
if (v > 0) {
Debug.Log(“back”);
back = true;
keepsideright = false;
keepside = false;
walk = false;
walkright = false;
front = false;
speed = 0;
}
animate.SetBool(“keepsideleft”, keepsideleft);
animate.SetBool(“front”, front);
animate.SetBool(“keepsideright”, keepsideright);
animate.SetBool(“walkleft”, walkleft);
animate.SetBool(“walkright”, walkright);
animati.SetBool(“back”, back);
}
}
obs.: i changed some name for easier understanding like front and back, i’m not using diferent names in animator and script.