Skip to content
Snippets Groups Projects
Commit c47f62d5 authored by v.bloch's avatar v.bloch
Browse files

fixation du bug de deplacement acceleré pour le deplacement en diagonal

parent b255064a
No related merge requests found
...@@ -5,19 +5,31 @@ ...@@ -5,19 +5,31 @@
using UnityEngine; using UnityEngine;
public enum PlayerState
{
walk,
interact
}
public class PlayerMovement : MonoBehaviour public class PlayerMovement : MonoBehaviour
{ {
public float speed; public float speed;
private Rigidbody2D myRigidbody; private Rigidbody2D myRigidbody;
private Vector3 change; private Vector3 change;
private Animator animator; private Animator animator;
public PlayerState currentState;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
currentState = PlayerState.walk;
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
myRigidbody = GetComponent<Rigidbody2D>(); myRigidbody = GetComponent<Rigidbody2D>();
animator.SetFloat("moveX", 0);
animator.SetFloat("moveY", -1);
} }
// Update is called once per frame // Update is called once per frame
...@@ -28,7 +40,11 @@ public class PlayerMovement : MonoBehaviour ...@@ -28,7 +40,11 @@ public class PlayerMovement : MonoBehaviour
change.x = Input.GetAxisRaw("Horizontal"); change.x = Input.GetAxisRaw("Horizontal");
change.y = Input.GetAxisRaw("Vertical"); change.y = Input.GetAxisRaw("Vertical");
UpdateAnimationAndMove(); if(currentState == PlayerState.walk)
{
UpdateAnimationAndMove();
}
Vector3 pos = Camera.main.WorldToViewportPoint(transform.position); Vector3 pos = Camera.main.WorldToViewportPoint(transform.position);
pos.x = Mathf.Clamp01(pos.x); pos.x = Mathf.Clamp01(pos.x);
...@@ -38,6 +54,7 @@ public class PlayerMovement : MonoBehaviour ...@@ -38,6 +54,7 @@ public class PlayerMovement : MonoBehaviour
void MoveCharacter() void MoveCharacter()
{ {
change.Normalize();
myRigidbody.MovePosition(transform.position + change * speed * Time.deltaTime); myRigidbody.MovePosition(transform.position + change * speed * Time.deltaTime);
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment