Beispiel #1
0
        /// <summary>
        /// The character should spawn with the specified position and rotation.
        /// </summary>
        private void SpawnLocal(Vector3 position, Quaternion rotation)
        {
            m_RespawnEvent = null;

            m_Controller.SetPosition(position);
            m_Controller.SetRotation(rotation);
            EventHandler.ExecuteEvent(m_GameObject, "OnRespawn");
        }
Beispiel #2
0
        /// <summary>
        /// Use a demo SpawnSelection component to respawn.
        /// </summary>
        private void Respawn()
        {
            var spawnLocation = CleanSpawnSelection.GetSpawnLocation();

            m_CharacterController.SetPosition(spawnLocation.position);
            m_CharacterController.SetRotation(spawnLocation.rotation);
            if (m_CurrentGenre == Genre.Shooter || m_CurrentGenre == Genre.Adventure || m_CurrentGenre == Genre.Platformer || m_CurrentGenre == Genre.RPG)
            {
                m_CameraController.ImmediatePosition();
            }
            else if (m_CurrentGenre == Genre.TopDown || m_CurrentGenre == Genre.PointClick)
            {
                m_CameraController.ImmediatePosition(Quaternion.Euler(53.2f, 0, 0));
            }
            else
            {
                m_CameraController.ImmediatePosition(Quaternion.Euler(26.56505f, 0, 0));
            }
        }
Beispiel #3
0
        /// <summary>
        /// The genre has been switched. Update the various object references.
        /// </summary>
        private void GenreSwitched()
        {
            switch (m_CurrentGenre)
            {
            case Genre.Shooter:
                m_CameraHandler.ZoomStateName = "Zoom";
                m_CameraController.ChangeState("TopDown", false);
                m_CameraController.ChangeState("ThirdPerson", true);
                m_Crosshairs.SetActive(true);
                m_WeaponWheel = m_CombatWeaponWheel;
                break;

            case Genre.Adventure:
                m_WeaponWheel = m_AdventureWeaponWheel;
                break;

            case Genre.RPG:
                m_CameraController.ChangeState("ThirdPerson", false);
                m_CameraController.ChangeState("RPG", true);
                m_WeaponWheel = m_RPGWeaponWheel;
                break;

            case Genre.Platformer:
                m_CameraHandler.ZoomStateName = "Zoom";
                m_CameraController.ChangeState("RPG", false);
                m_CameraController.ChangeState("ThirdPerson", true);
                m_Crosshairs.SetActive(true);
                m_Pseudo3DObjects.SetActive(false);
                m_WeaponWheel = m_CombatWeaponWheel;
                break;

            case Genre.Pseudo3D:
                m_CameraHandler.ZoomStateName = string.Empty;
                m_CameraController.ChangeState("ThirdPerson", false);
                m_CameraController.ChangeState("Pseudo3D", true);
                m_Crosshairs.SetActive(false);
                m_Pseudo3DObjects.SetActive(true);
                m_WeaponWheel = m_CombatWeaponWheel;
                break;

            case Genre.TopDown:
                m_CharacterController.Movement = RigidbodyCharacterController.MovementType.TopDown;
                m_CameraController.ChangeState("Pseudo3D", false);
                m_CameraController.ChangeState("TopDown", true);
                m_Crosshairs.SetActive(false);
                m_Pseudo3DObjects.SetActive(false);
                break;

            case Genre.PointClick:
                m_CharacterController.Movement = RigidbodyCharacterController.MovementType.PointClick;
                m_Crosshairs.SetActive(false);
                break;
            }
            m_WeaponWheel.SetActive(true);
            for (int i = 0; i < m_ItemPickups.childCount; ++i)
            {
                m_ItemPickups.GetChild(i).gameObject.SetActive(true);
            }

            // Start fresh.
            if (m_HasLoaded[(int)m_CurrentGenre])
            {
                m_CharacterInventory.RemoveAllItems(false);
                m_CharacterInventory.LoadDefaultLoadout();
            }
            m_CharacterAnimatorMonitor.PlayDefaultStates();
            Respawn();

            // Update Blitz.
            var enableBlitz = m_CurrentGenre == Genre.Shooter || m_CurrentGenre == Genre.Adventure || m_CurrentGenre == Genre.Platformer || m_CurrentGenre == Genre.RPG;

            if (enableBlitz)
            {
                m_BlitzCharacterController.TryStopAllAbilities();
                m_BlitzCharacterController.SetPosition(m_BlitzPosition);
                m_BlitzCharacterController.SetRotation(m_BlitzRotation);
            }
            m_Blitz.SetActive(enableBlitz);
        }
Beispiel #4
0
        /// <summary>
        /// Local method to move to the target position/rotation at the move speed. The onComplete action will be called after the character has arrived.
        /// </summary>
        /// <param name="targetPosition">The target position.</param>
        /// <param name="targetRotation">The target rotation.</param>
        /// <param name="minMoveSpeed">The minimum speed to move positions.</param>
        /// <param name="onComplete">The action to call after the character has arrived.</param>
        private IEnumerator MoveToTargetLocal(Vector3 targetPosition, Quaternion targetRotation, float minMoveSpeed, Action onComplete)
        {
            if (s_EndOfFrame == null)
            {
                s_EndOfFrame = new WaitForFixedUpdate();
            }

            // Use the existing speed if it is greater then the minimum so the character will smoothly move to the target.
            var moveSpeed = m_Controller.InputVector.magnitude > minMoveSpeed ? m_Controller.InputVector.magnitude : minMoveSpeed;

            // Stop any existing velocities.
            m_Controller.StopMovement();

            // Gradually move towards the target position/rotation.
            var prevPosition = m_Transform.position;
            var startOffset  = m_Transform.InverseTransformPoint(targetPosition);

            while (true)
            {
                // Rotate towards the target rotation.
                m_Controller.SetRotation(Quaternion.Slerp(m_Transform.rotation, targetRotation, m_Controller.RotationSpeed * Time.deltaTime));

                // Use Root Motion to determine how far to move.
                var position = m_Transform.position;
                position.x = Mathf.MoveTowards(position.x, targetPosition.x, m_Controller.RootMotionForce.x > 0.05f ? m_Controller.RootMotionForce.x : 0.05f);
                position.z = Mathf.MoveTowards(position.z, targetPosition.z, m_Controller.RootMotionForce.z > 0.05f ? m_Controller.RootMotionForce.z : 0.05f);
                m_Controller.SetPosition(position);

                // Keep walking towards the target position. Slow down as the character gets closer.
                var offset   = m_Transform.InverseTransformPoint(targetPosition);
                var strength = (startOffset.x < 0.001f ? 0 : offset.x / startOffset.x);
                m_AnimatorMonitor.SetHorizontalInputValue(moveSpeed * strength);
                strength = (startOffset.z < 0.001f ? 0 : offset.z / startOffset.z);
                m_AnimatorMonitor.SetForwardInputValue(moveSpeed * strength);

                // Break if the character has arrived at the destination. Perform the check after the movements so it doesn't have to wait for a frame to pass before checking again.
                if (Mathf.Abs(m_Transform.position.x - targetPosition.x) < 0.1f && Mathf.Abs(m_Transform.position.z - targetPosition.z) < 0.1f &&
                    Quaternion.Angle(m_Transform.rotation, targetRotation) < 0.1f)
                {
                    break;
                }

                // If the character is stuck then stop trying to move.
                if ((position - prevPosition).sqrMagnitude < 0.00001f)
                {
                    break;
                }

                prevPosition = position;
                yield return(s_EndOfFrame);
            }

            // The character has arrived. Set the position and rotation to its final position.
            m_Controller.SetPosition(targetPosition);
            m_Controller.SetRotation(targetRotation);
            // The character is no longer moving.
            m_Controller.StopMovement();

            // The coroutine has ended.
            m_MoveToTargetRoutine = null;

            // Let the calling ability know that the character has arrived.
            onComplete();
        }