// Update is called once per frame void Update() { truncatedPosition = VectorUtils.Truncate(ghost.position); if (ShouldChangeDirection()) { if (reverseDirection) { // Happens when ghosts change to certain states ghostController.SetDirection(VectorUtils.Opposite(lastDirectionDecided)); lastPositionDecided = truncatedPosition; reverseDirection = false; } else { ghostController.SetDirection(DecideNextDirection()); lastPositionDecided = truncatedPosition; } } }
private void GoTo(Vector2 position) { ghostController.SetDirection((position - rigidbody2D.position).normalized); }