Reputation: 45
Okay so here is a video showing the problem that is pretty self explanatory https://youtu.be/7701UK0ijy4
My problem is purely that when I switch to the Running Left animation, it still plays the Running Right animation instead
Before you read this list just know, none if it had any effect. So far, I have tried setting Speed of Main_Run_Left to -1. I have checked the Mirror box. I have deleted all animations and reset them.
Edit: I switched Running_Left animation with a different monster animation and it kinda worked briefly? as in it was playing running_Left with the other monster animation set instead? Like I said briefly, it went back to running right while going left.
public Animator anim;
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
if (horizontalMove > .001)
{
anim.SetBool("Running Right", true);
anim.SetBool("Running Left", false);
anim.SetBool("Chillin", false);
}
else if (horizontalMove < -.001)
{
anim.SetBool("Running Left", true);
anim.SetBool("Running Right", false);
anim.SetBool("Chillin", false);
}
else
{
anim.SetBool("Chillin", true);
anim.SetBool("Running Left", false);
anim.SetBool("Running Right", false);
}
Upvotes: 0
Views: 1230
Reputation: 807
What you're doing is kind of weird. You have a walking right animation AND a walking left animation, even though they're mirror flips of each other. How about deleting the walking left animation and renaming the other one to just 'Walking'? Then delete all the bools in your animator and replace them with a single one called 'Moving'. The condition to transition from chillin to walking is whether the 'Moving' bool is true, and vice versa. Then in code, you flip the sprite when its horizontal is less than zero. I posted a script below that shows what I'm talking about.
using UnityEngine;
public class Player : MonoBehaviour
{
[SerializeField]
private float _speed;
private Rigidbody2D _rb;
private Animator _anim;
private SpriteRenderer _sprite;
void Start()
{
_rb = GetComponent<Rigidbody2D>();
_anim = GetComponent<Animator>();
_sprite = GetComponent<SpriteRenderer>();
}
void FixedUpdate()
{
Move();
}
private void Move()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(horizontal, vertical);
_rb.velocity = movement * _speed;
_anim.SetBool("Moving", horizontal != 0);
if (horizontal != 0)
Flip(horizontal > 0);
}
private void Flip(bool facingRight)
{
_sprite.flipX = !facingRight;
}
}
Upvotes: 2