/// <summary> /// Tries to start the ability at the specified index. /// </summary> /// <param name="index">The ability index to start.</param> private void TryStartAbility(int index) { #if ENABLE_MULTIPLAYER CmdTryStartAbility(index); // Execute the method on the local instance. Use isClient instead of isServer because the client and server may be the same instance // in which case the method will be called with the Rpc call. if (!isClient) { #endif m_Controller.TryStartAbility(m_Controller.Abilities[index]); #if ENABLE_MULTIPLAYER } #endif }
/// <summary> /// Updates the velocity and look rotation using the off mesh link. /// </summary> /// <param name="velocity">The desired velocity.</param> /// <param name="lookRotation">The desired look rotation.</param> protected virtual void UpdateOffMeshLink(ref Vector3 velocity, ref Quaternion lookRotation) { if (m_NavMeshAgent.currentOffMeshLinkData.linkType == OffMeshLinkType.LinkTypeDropDown || m_NavMeshAgent.currentOffMeshLinkData.linkType == OffMeshLinkType.LinkTypeJumpAcross) { // Ignore the y difference when determining a look direction and velocity. // This will give XZ distances a greater impact when normalized. var direction = m_NavMeshAgent.currentOffMeshLinkData.endPos - m_Transform.position; direction.y = 0; if (direction.sqrMagnitude > 0.1f || m_Controller.Grounded) { velocity = m_Transform.InverseTransformPoint(m_NavMeshAgent.currentOffMeshLinkData.endPos); velocity.y = 0; velocity.Normalize(); } // Jump if the agent hasn't jumped yet. if (m_JumpAbility != null && m_NavMeshAgent.currentOffMeshLinkData.linkType == OffMeshLinkType.LinkTypeJumpAcross) { if (!m_JumpAbility.IsActive && (m_FallAbility == null || !m_FallAbility.IsActive)) { m_Controller.TryStartAbility(m_JumpAbility); // Only update the LookRotation when the character starts jumping to prevent the agent from rotating while in the air. lookRotation = Quaternion.LookRotation(direction); } } } }
public void Run() { characterController.TryStartAbility(speedChange); }