/// <summary> /// The ability has stopped running. /// </summary> protected override void AbilityStopped() { // The RideID will still be ride if the ability is force stopped. if (m_RideID == RideID.Ride) { StartDismount(); } base.AbilityStopped(); EventHandler.UnregisterEvent(m_GameObject, "OnAnimatorMounted", Mounted); EventHandler.UnregisterEvent(m_GameObject, "OnAnimatorDismounted", Dismounted); m_Rigidbody.useGravity = true; m_Controller.ForceRootMotion = false; m_RideID = RideID.None; #if !ENABLE_MULTIPLAYER if (m_CameraMonitor != null && m_RPGCamera) { m_CameraMonitor.ViewMode = CameraMonitor.CameraViewMode.RPG; m_RPGCamera = false; } #endif // Reenable the collision between the character colliders and the rideable colliders. var rideableColliders = m_RideableObject.GetComponentsInChildren <Collider>(); for (int i = 0; i < rideableColliders.Length; ++i) { if (rideableColliders[i].enabled) { LayerManager.RevertCollision(rideableColliders[i]); } } }
/// <summary> /// The character has mounted on the object. Start to ride the object. /// </summary> private void Mounted() { if (m_RideID == RideID.Mount) { m_RideID = RideID.Ride; #if !ENABLE_MULTIPLAYER // Change to third person mode if the camera view mode is set to RPG. if (m_CameraMonitor != null && m_CameraMonitor.ViewMode == CameraMonitor.CameraViewMode.RPG) { m_RPGCamera = true; m_CameraMonitor.ViewMode = CameraMonitor.CameraViewMode.ThirdPerson; } else { m_RPGCamera = false; } #endif m_RideableObject.Mounted(); m_Rigidbody.isKinematic = true; m_Transform.parent = m_RideableObject.MountParent; m_AnimatorMonitor.DetermineStates(); // If the SpeedChange ability is active then also activate it on the RideableObject. if (m_SpeedChange.IsActive) { var rideableSpeedChange = Utility.GetComponentForType <SpeedChange>(m_RideableObject.gameObject); if (rideableSpeedChange != null && !rideableSpeedChange.IsActive) { Utility.GetComponentForType <RigidbodyCharacterController>(m_RideableObject.gameObject).TryStartAbility(rideableSpeedChange); } } } }
/// <summary> /// The ability has been started. /// </summary> protected override void AbilityStarted() { m_RideID = RideID.None; m_Rigidbody.useGravity = false; m_Controller.ForceRootMotion = true; base.AbilityStarted(); EventHandler.RegisterEvent(m_GameObject, "OnAnimatorMounted", Mounted); EventHandler.RegisterEvent(m_GameObject, "OnAnimatorDismounted", Dismounted); // Ignore the collision between the character colliders and the rideable colliders. var rideableColliders = m_RideableObject.GetComponentsInChildren <Collider>(); for (int i = 0; i < rideableColliders.Length; ++i) { if (rideableColliders[i].enabled) { for (int j = 0; j < m_Colliders.Length; ++j) { if (m_Colliders[j].enabled && m_Colliders[j].gameObject.activeSelf) { LayerManager.IgnoreCollision(rideableColliders[i], m_Colliders[j]); } } } } // Move into mount position. var closestMount = m_RideableObject.GetClosestMount(m_Transform.position); MoveToTarget(closestMount.position, closestMount.rotation, m_MinMoveToTargetSpeed, InPosition); }
/// <summary> /// The character should start to dismount from the object. /// </summary> private void StartDismount() { if (m_RideID == RideID.Ride) { m_RideID = RideID.Dismount; m_RideableObject.Dismount(); m_Rigidbody.isKinematic = false; // The GameObject will be inactive when the game is stopping. if (m_GameObject.activeInHierarchy) { m_Transform.parent = null; } m_AnimatorMonitor.DetermineStates(); } }
/// <summary> /// The character has arrived at the mount position and is ready to play the mount animation. /// </summary> private void InPosition() { m_RideID = RideID.Mount; m_AnimatorMonitor.DetermineStates(); }