Question by
Eiskrieg · Apr 24, 2016 at 06:58 PM ·
sprite2d gamecharactercontrolleranimationsz-axis
2.5 D, Unity 5, Animations wont work while moving on the Z-Axis.
Hello people,
maybe im to blind to figure it correct out, but somehow the animations of my Playersprit wont work when it moves on the Z-Axis. Walking on the X is just fine.
Normaly the player is supposed to run the idle animation while not moving, but when the speed is greater then 0,1 he starts the idle animation. Somehow it wont on the Z Axis.
Maybe you can help me :X
public float maxSpeed = 2;
public float jumpForce = 550;
[HideInInspector]
public bool lookingright = true;
private Rigidbody2D rb2d;
private Animator anim;
// Use this for initialization
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
float vert = Input.GetAxis("Vertical");
float hor = Input.GetAxis("Horizontal");
transform.position += new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical")) * Time.deltaTime * maxSpeed;
anim.SetFloat("Speed", Mathf.Abs(vert));
anim.SetFloat("Speed", Mathf.Abs(hor));
// rb2d.velocity = new Vector3(hor * maxSpeed, rb2d.velocity.y);
//rb2d.velocity = new Vector3(vert * maxSpeed, rb2d.velocity.y);
}
Thank you very much :)
Comment
Best Answer
Answer by Eiskrieg · Apr 24, 2016 at 07:11 PM
Hello me again I just solved it xD
Its
anim.SetFloat("Speed", Mathf.Abs(vert+hor));
My fault, but thanks anyway :)