private bool CheckIfMovement() { Vector3 newPosition = grid.WorldToGridFixed(transform.position); float distance = Vector3.Distance(newPosition, grid.WorldToGridFixed(oldPosition)); return(distance > 0.5f); }
private List <Personality> GetNeighbourPersonalities(Vector3 curPos) { List <Personality> neighbourPersonalities = new List <Personality>(); Vector3 position = grid.WorldToGridFixed(curPos); foreach (Personality personality in characters) { Vector3 reference = grid.WorldToGridFixed(personality.transform.position); if (reference == position) { continue; } bool isNeighbour = false; if (Mathf.Abs(reference.x - position.x) < 1.1f && Mathf.Abs(reference.y - position.y) < 0.1f) {//straight above or below isNeighbour = true; } else { if (Mathf.RoundToInt(reference.y) % 2 == 0) {//two cases, depending on whether the x-coordinate is even or odd //neighbours are either strictly left or right of the switch or right/left and one unit below if (Mathf.Abs(reference.y - position.y) < 1.1f && position.x - reference.x < 0.1f && position.x - reference.x > -1.1f) { isNeighbour = true; } } else {//x-coordinate odd //neighbours are either strictly left or right of the switch or right/left and one unit above if (Mathf.Abs(reference.y - position.y) < 1.1f && reference.x - position.x < 0.1f && position.x - reference.x < 1.1f) { isNeighbour = true; } } } if (isNeighbour) { neighbourPersonalities.Add(personality); } } return(neighbourPersonalities); }