From c47f62d5efcfc4c18b25d5ae980a1b18ba34dc6b Mon Sep 17 00:00:00 2001
From: "v.bloch" <v.bloch@etu.unistra.fr>
Date: Sat, 27 Mar 2021 14:59:59 +0100
Subject: [PATCH] =?UTF-8?q?fixation=20du=20bug=20de=20deplacement=20accele?=
 =?UTF-8?q?r=C3=A9=20pour=20le=20deplacement=20en=20diagonal?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Assets/Scripts/Player/PlayerMovement.cs | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs
index 75112bd..3f60686 100644
--- a/Assets/Scripts/Player/PlayerMovement.cs
+++ b/Assets/Scripts/Player/PlayerMovement.cs
@@ -5,19 +5,31 @@
 
 using UnityEngine;
 
+public enum PlayerState
+{
+    walk,
+    interact
+}
+
 public class PlayerMovement : MonoBehaviour
 {
     public float speed;
     private Rigidbody2D myRigidbody;
     private Vector3 change;
     private Animator animator;
+    public PlayerState currentState;
 
     // Start is called before the first frame update
     void Start()
     {
+        currentState = PlayerState.walk;
+
         animator = GetComponent<Animator>();
         myRigidbody = GetComponent<Rigidbody2D>();
 
+        animator.SetFloat("moveX", 0);
+        animator.SetFloat("moveY", -1);
+
     }
 
     // Update is called once per frame
@@ -28,7 +40,11 @@ public class PlayerMovement : MonoBehaviour
         change.x = Input.GetAxisRaw("Horizontal");
         change.y = Input.GetAxisRaw("Vertical");
 
-        UpdateAnimationAndMove();
+        if(currentState == PlayerState.walk)
+        {
+            UpdateAnimationAndMove();
+        }
+
 
         Vector3 pos = Camera.main.WorldToViewportPoint(transform.position);
         pos.x = Mathf.Clamp01(pos.x);
@@ -38,6 +54,7 @@ public class PlayerMovement : MonoBehaviour
 
     void MoveCharacter()
     {
+        change.Normalize();
         myRigidbody.MovePosition(transform.position + change * speed * Time.deltaTime);
     }
 
-- 
GitLab