- Home /
Anyone know how to see if the player is moving backwards?
Heres my code for a paper mario style flip animation: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class srRotate : MonoBehaviour
{
public SpriteRenderer SR;
public Player target;
public Animator flipAnim;
private bool movingBackwards;
// Update is called once per frame
void Update()
{
if (!SR.flipX && target.moveDirection.x < 0)
{
SR.flipX = true;
flipAnim.SetTrigger("Flip");
}
else if (SR.flipX && target.moveDirection.x > 0)
{
SR.flipX = false;
flipAnim.SetTrigger("Flip");
}
if (!movingBackwards && target.moveDirection.y < 0)
{
movingBackwards = true;
flipAnim.SetTrigger("Flip");
}
else if (movingBackwards && target.moveDirection.y > 0)
{
movingBackwards = false;
flipAnim.SetTrigger("Flip");
}
}
}
Comment
Put a break point at line 32..? ;)
What's the problem with this code? You're setting movingBackwards, does this not work? What's happening instead? plz give more context
I figured it out, It was a bug in my players movement script, But thx for the help :D!
Your answer
Follow this Question
Related Questions
Why are transform values in inspector different from animation tab? 2 Answers
Can I get a the transform from a bone animation? 0 Answers
Unity Multiplayer - Animations - mesh subobject movements conveyed 1 Answer
Why is the if condition returning true ? 0 Answers
Mecanim blend moves character? 1 Answer