From ebf4b0e98283e9a46487d1fd469af1fc6aec85b1 Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Sat, 3 Feb 2024 20:04:50 +0100 Subject: [PATCH] Player now turns to their move direction --- .../Scripts/Player/PlayerAnimationHandler.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Player/PlayerAnimationHandler.cs b/Assets/Scripts/Player/PlayerAnimationHandler.cs index d131f57..ef54b41 100644 --- a/Assets/Scripts/Player/PlayerAnimationHandler.cs +++ b/Assets/Scripts/Player/PlayerAnimationHandler.cs @@ -5,11 +5,30 @@ using UnityEngine; public class PlayerAnimationHandler : MonoBehaviour { Animator animator; + SpriteRenderer sp; + + Vector3 prevPos; + void Start() { animator = GetComponentInChildren(); - + sp = GetComponentInChildren(); } + + private void Update() + { + if ((transform.position - prevPos).x > 0.1f) + { + sp.flipX = false; + } + else if ((transform.position - prevPos).x < -0.1f) + { + sp.flipX = true; + } + + prevPos = transform.position; + } + public void Idle() { animator.SetTrigger("Idle");