From 45ca06e33f36308779cbda9a9ac528549ecd75ee Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Sat, 27 Apr 2019 19:19:46 +0200 Subject: [PATCH] Fixed player movement script It works --- Assets/Scripts/Player.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index 86df64c..0a2d84c 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -29,30 +29,33 @@ public class Player : MonoBehaviour void CheckForMovementInput() { bool hasMoved = false; + Vector2Int posizione = new Vector2Int(); + posizione.x = (int)transform.position.x+1; + posizione.y = (int)transform.position.y+1; if (Input.GetKeyDown(KeyCode.A)) { - if (map.CanMoveTo(Vector2Int.left)) { + if (map.CanMoveTo(posizione + Vector2Int.left)) { transform.Translate(Vector3.left); hasMoved = true; } } else if (Input.GetKeyDown(KeyCode.D)) { - if (map.CanMoveTo(Vector2Int.right)) { + if (map.CanMoveTo(posizione + Vector2Int.right)) { transform.Translate(Vector3.right); hasMoved = true; } } else if (Input.GetKeyDown(KeyCode.W)) { - if (map.CanMoveTo(Vector2Int.up)) { + if (map.CanMoveTo(posizione + Vector2Int.up)) { transform.Translate(Vector3.up); hasMoved = true; } } else if (Input.GetKeyDown(KeyCode.S)) { - if (map.CanMoveTo(Vector2Int.down)) { + if (map.CanMoveTo(posizione + Vector2Int.down)) { transform.Translate(Vector3.down); hasMoved = true; }