Beispiel #1
0
        /// <summary>
        /// Move this character by sending input to the input system.
        /// </summary>
        private void HandleMovement()
        {
            // Stop the current input direction
            inputDirection *= 0.0f;

            // Try to calculate a new input direction
            if (movementPath.corners != null && movementPath.corners.Length > 0)
            {
                if (pathIndex >= movementPath.corners.Length || pathIndex < 0)
                {
                    // Clear the nav path
                    movementPath.ClearCorners();
                    pathIndex = 0;
                }
                else
                {
                    // Set the position to move to
                    targetPosition = movementPath.corners[pathIndex];

                    // Get the direction from the position
                    inputDirection = targetPosition - _transform.position;

                    // Look in the direction we are moving.
                    lookAt = new Vector3(targetPosition.x, _transform.position.y, targetPosition.z);

                    if (pathIndex == movementPath.corners.Length - 1)
                    {
                        lookAt += _transform.forward * 10;
                    }

                    lookAt = Utility.Utilities.mainCamera.WorldToScreenPoint(lookAt);

                    inputManager.HandleLook(lookAt);

                    // Check if we are close enough to stop or move on
                    if (Vector3.Distance(_transform.position, targetPosition) <= stoppingDistance)
                    {
                        // Move to the next item in the array
                        pathIndex++;
                    }
                }
            }

            // Convert the input from a vector3 into a vector2
            inputDirection.y = inputDirection.z;
            inputDirection.z = 0;

            // Feed the input to the input manager.
            inputManager.HandleMovement(inputDirection);
        }