private void SlideWalk() { Vector2Int beforeMove = new Vector2Int(gridMovement.x, gridMovement.y); Vector2 slideDirection = InputToDirection(); Debug.Log(string.Format("X: {0} Y: {1}", beforeMove.x, beforeMove.y)); //uses the position before moving to determine whether or not object has hit a wall. //it will then stop sliding. Vector2Int oldPosition = new Vector2Int(gridMovement.x, gridMovement.y); MoveInDirection(slideDirection); int counter = 0; bool hasCollided = false; while (!(oldPosition.Equals(new Vector2Int(gridMovement.x, gridMovement.y)))) { oldPosition = new Vector2Int(gridMovement.x, gridMovement.y); hasCollided = gridMovement.isEnemyHere(oldPosition + ConvertToVectorInt(slideDirection)); MoveInDirection(slideDirection); //avoids infinite loop counter++; if (counter > 50) { Debug.Log("INFINITE!!!"); return; } } //if you moved, host loses health Debug.Log(hasCollided); if ((!beforeMove.Equals(gridMovement.GetPositionVector2Int()))) { if (!(hasCollided)) { manager.DecrementLivesLeft(); //sets direction gridMovement.direction = InputToDirection(); gridAnimator.TriggerWalk(); } else { if (!isDead) { manager.DecrementLivesLeft(); } } } }