private void ChangeBehaviour(AiBehaviour behaviour, float transitionTime) { if (_activeAi != null) { _activeAi.End(); } // Stop movement prior to behaviour change, or else enemy will move towards its // old movement direction during the wait period. _motor.StopUntilResumed(); // Set new behaviour _activeAi = GetBehaviour(behaviour); _activeAi.Begin(); _activeBehaviour = behaviour; // Simulate transition to new behaviour by waiting for a short time Wait(transitionTime); }