Skip to content
Snippets Groups Projects
Commit 9aeae85b authored by Raffael Di Pietro's avatar Raffael Di Pietro
Browse files

CORRECTION DU BUG DE LAG DANS LES DEPLACEMENTS !!(youhouu)

parent 4feb00ca
No related merge requests found
......@@ -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
......
......@@ -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);
}
}
}
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