diff --git a/Assets/Prefabs/GUI/BarreDenature.prefab b/Assets/Prefabs/GUI/BarreDenature.prefab index f5f616da65bf35ec986cd84ad31c0cdb56f5d525..514c4d46c829ac09627b1d2e2fb02d7742437f8e 100644 --- a/Assets/Prefabs/GUI/BarreDenature.prefab +++ b/Assets/Prefabs/GUI/BarreDenature.prefab @@ -802,7 +802,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 0.44705883} + m_Color: {r: 1, g: 1, b: 1, a: 0.42745098} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index da1b0b976b422cc1517e0e7d0c391655767177db..6dcf98ae44a0e6d19ea9feec4e81648dc8b57624 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -15,7 +15,7 @@ public class PlayerMovement : MonoBehaviour { public float speed; private Rigidbody2D myRigidbody; - private Vector3 change; + private Vector2 moveDirection; private Animator animator; public PlayerState currentState; public int stage = 0; @@ -39,22 +39,52 @@ public class PlayerMovement : MonoBehaviour // Update is called once per frame void Update() { - - change = Vector3.zero; - change.x = Input.GetAxisRaw("Horizontal"); - change.y = Input.GetAxisRaw("Vertical"); + ProcessInputs(); if(currentState == PlayerState.walk) { UpdateAnimationAndMove(); } - Vector3 pos = Camera.main.WorldToViewportPoint(transform.position); pos.x = Mathf.Clamp01(pos.x); pos.y = Mathf.Clamp01(pos.y); transform.position = Camera.main.ViewportToWorldPoint(pos); + gameIntelligence(); + } + + private void FixedUpdate() + { + moveDirection.Normalize(); + myRigidbody.velocity = new Vector2(moveDirection.x * speed, moveDirection.y * speed); + } + + private void ProcessInputs() + { + float moveX = Input.GetAxisRaw("Horizontal"); + float moveY = Input.GetAxisRaw("Vertical"); + moveDirection = new Vector2(moveX, moveY); + } + + void UpdateAnimationAndMove() + { + if (moveDirection != Vector2.zero) + { + + animator.SetFloat("moveX", moveDirection.x); + animator.SetFloat("moveY", moveDirection.y); + + animator.SetBool("moving", true); + } + else + { + animator.SetBool("moving", false); + } + } + + void gameIntelligence() + { if (this.GetComponent<PlayerNature>().currentNature >= 100 && stage == 0) { GenerateMap.instance.generateBoutique(0, 1, "chaussure"); @@ -96,26 +126,4 @@ public class PlayerMovement : MonoBehaviour stage++; } } - - void MoveCharacter() - { - change.Normalize(); - myRigidbody.MovePosition(transform.position + change * speed * Time.deltaTime); - } - - void UpdateAnimationAndMove() - { - if (change != Vector3.zero) - { - MoveCharacter(); - animator.SetFloat("moveX", change.x); - animator.SetFloat("moveY", change.y); - - animator.SetBool("moving", true); - } - else - { - animator.SetBool("moving", false); - } - } }