Hello all, new poster/Unity user here.
I’ve been interested in making a 2d top-down rpg like game for a while now and decided to try with Unity. To learn how to make the 8 directional movement I decided to watch a several years old video tutorial on how to animate directional movement and the idle animation that plays when the movement stops.
I’ve been using this video:
Or “Topdown 2D RPG In Unity - 04 Idle & Face Correct Direction” by Hundred Fires Games on Youtube.
(The other three videos before this in the series just cover the setup, movement, and animation, which I don’t think I need help with).
Everything went well so far, the 8 directional movement animation is fine, until I got to the idle animation. it ends up automatically using the face down idle animation (facing towards the camera) no matter which direction once the movement ended. I want the player object to face whatever direction that the movement ended in.
Here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Rigidbody2D myRB;
private Animator myAnim;
[SerializeField]
private float speed;
// Start is called before the first frame update
void Start()
{
myRB = GetComponent<Rigidbody2D>();
myAnim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
myRB.velocity = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")) * speed;
myAnim.SetFloat("Movex", myRB.velocity.x);
myAnim.SetFloat("Movey", myRB.velocity.y);
if (Input.GetAxisRaw("Horizontal") == 1 || Input.GetAxisRaw("Horizontal") == -1 || Input.GetAxisRaw("Vertical") == 1 || Input.GetAxisRaw("Vertical") == -1) ;
{
myAnim.SetFloat("LastMovex", Input.GetAxisRaw("Horizontal"));
myAnim.SetFloat("LastMovey", Input.GetAxisRaw("Vertical"));
}
}
}
I would add images, but I can’t seem to upload from imgur.
I basically used the exact same script, animation, sprites, and directions as the video. Is there some little thing I’m missing? Is the problem a difference between versions?
Thanks.
edit: I am using Unity 2021.3.10f1