Пример #1
0
        private void HandleCharacterNavigation()
        {
            if (NavMesh.CalculatePath(Character.transform.position, Destination.position, NavMesh.AllAreas, _path))
            {
                _lastValidDestination = Destination.position;
            }
            else
            {
                NavMesh.CalculatePath(Character.transform.position, _lastValidDestination, NavMesh.AllAreas, _path);
            }

            AICharacterInputs characterInputs = new AICharacterInputs();

            int cornersCount = _path.GetCornersNonAlloc(_pathCorners);

            if (cornersCount > 1)
            {
                // Build the CharacterInputs struct
                characterInputs.MoveVector = (_pathCorners[1] - Character.transform.position).normalized;

                // Apply inputs to character
                Character.SetInputs(ref characterInputs);
            }
            else
            {
                // Build the CharacterInputs struct
                characterInputs.MoveVector = Vector3.zero;

                // Apply inputs to character
                Character.SetInputs(ref characterInputs);
            }
        }
Пример #2
0
        /// <summary>
        /// This is called every frame by MyAI in order to tell the character what its inputs are
        /// </summary>
        public void SetInputs(ref AICharacterInputs inputs)
        {
            // Move and look inputs
            _moveInputVector = inputs.MoveVector;

            if (_moveInputVector.sqrMagnitude == 0f)
            {
                _lookInputVector = Motor.CharacterForward;
            }
            else
            {
                _lookInputVector = Vector3.ProjectOnPlane(_moveInputVector, Motor.CharacterUp);
            }
        }