Fixed! So I wanted to say thank you to everyone who contributed - especially to vakabaka who provided some code to get me going. I think your code has allowed me to have the character facing diagonal more consistently. If possible, I’m still interested in vakabaka explaining some of the code and how the NoMoreDiagonal method works. I’m not too familar with IEnumerator, yield, StartCoroutine, or how WaitForSeconds works.
To deal with the animation lag, it was something rather simple that I had overlooked (I’m still quite new to Unity, and even newer to using animation). In the animation, “Fixed Duration” is ticked by default, and the animations were playing out, even if the next animation was queued. Right now I literally have 8 animations of one single sprite each, though now I have the groundwork laid I will likely have actual animations of a few sprites for each direction.
Any pitfalls I might want to consider before adding in additional sprites to each animation?
I see there’s a “Interruption Source” box, that allows you to select “Next State” as an option… so I imagine that may be a better choice than just unticking Fixed Duration, but I’ll cross that bridge when I get there.
Thank you again for pitching in ideas, questions, and code. Excited to be part of this community and hopefully this is the first step into being able to make some awesome projects.
Cheers,
Brodus
Updated video after working code/animation:
p.s. Just wanted to add that with the Fixed Duration unchecked, one of my other original scripts works well (on par I believe, and very similar, to vakabaka’s script). Any suggestions on why one might be better than the other performance wise? Or any issues I might run into?
using UnityEngine;
using System.Collections;
public class PlayerMovement2 : MonoBehaviour {
Animator anim;
public float speed = 5f;
private Vector2 movement;
float counter;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
counter = 0f;
//GetComponent<Rigidbody2D>().velocity = movement;
}
// Update is called once per frame
void FixedUpdate()
{
float inputX = Input.GetAxisRaw("Horizontal");
float inputY = Input.GetAxisRaw("Vertical");
movement = new Vector2(inputX, inputY);
if(Input.GetAxisRaw("Horizontal") != 0 && Input.GetAxisRaw("Vertical") != 0)
{
if (movement.y == 1 && movement.x == -1)
{
anim.SetTrigger("move_up_left");
counter = .1f;
}
if (movement.y == 1 && movement.x == 1)
{
anim.SetTrigger("move_up_right");
counter = .1f;
}
if (movement.y == -1 && movement.x == -1)
{
anim.SetTrigger("move_down_left");
counter = .1f;
}
if (movement.y == -1 && movement.x == 1)
{
anim.SetTrigger("move_down_right");
counter = .1f;
}
}
else if(counter <= 0)
{
if (movement.x == -1)
{
anim.SetTrigger("move_left");
}
if (movement.x == 1)
{
anim.SetTrigger("move_right");
}
if (movement.y == 1)
{
anim.SetTrigger("move_up");
}
if (movement.y == -1)
{
anim.SetTrigger("move_down");
}
counter = 0;
}
counter -= Time.deltaTime;
Debug.Log(counter);
transform.Translate(movement * speed * Time.deltaTime);
}
}