// Update is called once per frame void Update() { Vector2 player_direction = new Vector2( Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical") ); if (player_direction.SqrMagnitude() < 0.05f) { // The input is REALLY small (probably zero), // so don't change the desired direction return; } //Only Vertical or Horital movements allowed so with retrict it if (Mathf.Abs(player_direction.x) >= Mathf.Abs(player_direction.y)) { player_direction.y = 0; } else { player_direction.x = 0; } mazeMover.SetNewDirection(player_direction.normalized); }
public void ResetToStartingPos() { transform.GetChild(0).transform.localScale = Vector3.one; transform.GetChild(0).transform.rotation = Quaternion.Euler(Vector3.zero); transform.GetChild(0).transform.localPosition = Vector3.zero; transform.position = Starting_position; maze_mover.SetNewDirection(Vector2.zero); maze_mover.ResetTarget(); }
public Vector2 ChooseDirection(MazeMover maze_mover, bool can_use_gate) { Vector3 current_direction = maze_mover.GetDirection(); Vector2 newDir = Vector2.zero; // Are we going into a wall ? if (!maze_mover.IsNextMoveLegal(can_use_gate)) { newDir = maze_mover.GetDirection(); newDir.x *= -1f; newDir.y *= -1f; maze_mover.SetNewDirection(newDir); } //Do we continue straight ? if (Random.Range(0f, 1f) < 0.5) { return(maze_mover.GetDirection()); } //We change direction //Are we moving left/right ? THen go up or down and vice versa if (Mathf.Abs(current_direction.x) > 0) { newDir.y = Random.Range(0, 2) == 0 ? -1 : 1; } else { newDir.x = Random.Range(0, 2) == 0 ? -1 : 1; } return(newDir); }