Question by
cottonbloom · Dec 18, 2018 at 08:52 PM ·
animation2dunity 2d
Unity 2D Animation issue ver. 2017.3
I'm currently using Unity 2017.3 (because my teacher refuses to update) and am following the 2D Zelda-like rpg tutorial by Mister Taft Creates. I've come across some issues in the 4 way sprite animation, where animation transitions are buggy wont function properly. It'll display the walking animation in idle mode, and will play idle animations when buttons are pressed- it won't match the direction pressed and delays transitions.
Here are my blend trees:
Here are the Player components:
Here is the Player Movement code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed;
private Rigidbody2D myRigidbody;
private Vector3 change;
private Animator animator;
void Start ()
{
animator = GetComponent<Animator>();
myRigidbody = GetComponent<Rigidbody2D>();
}
void Update ()
{
change = Vector3.zero;
change.x = Input.GetAxisRaw("Horizontal");
change.y = Input.GetAxis("Vertical");
UpdateAnimationAndMove();
}
void UpdateAnimationAndMove()
{
if (change != Vector3.zero)
{
MoveCharacter();
animator.SetFloat("moveX", change.x);
animator.SetFloat("moveY", change.y);
animator.SetBool("moving", true);
}
else
{
animator.SetBool("moving", false);
}
}
void MoveCharacter()
{
myRigidbody.MovePosition(
transform.position + change * speed * Time.deltaTime
);
}
}
bugged-out-unity-animation.png
(242.3 kB)
player.png
(59.5 kB)
Comment