示例#1
0
        /// <summary>
        /// Handles input for manipulating the camera yaw (rotating around).
        /// </summary>
        /// <param name="camera"></param>
        /// <returns></returns>
        private bool ProcessCameraYawPitch(ref CameraFollowComponent camera)
        {
            if (MathUtils.IsZero(Input.GetAxis("Mouse 2")))
            {
                return(false);
            }

            camera.Yaw   += Input.GetAxis("Mouse X");
            camera.Pitch -= Input.GetAxis("Mouse Y");

            return(true);
        }
示例#2
0
        /// <summary>
        /// Handles input for zooming the camera in and out.
        /// </summary>
        /// <param name="camera"></param>
        /// <returns></returns>
        private bool ProcessCameraZoom(ref CameraFollowComponent camera)
        {
            float scroll = Input.GetAxis("Mouse Scroll Wheel");

            if (!MathUtils.IsZero(scroll))
            {
                camera.Zoom -= scroll;
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Processes the horizontal movement input from the player to move the entity along the xz plane.
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="camera"></param>
        private void ProcessMovement(ref CharacterControllerComponent controller, ref CameraFollowComponent camera)
        {
            float movementX = (Input.GetAxis("Move Right") > 0.0f ? 1.0f : 0.0f) + (Input.GetAxis("Move Left") > 0.0f ? -1.0f : 0.0f);
            float movementZ = (Input.GetAxis("Move Forward") > 0.0f ? 1.0f : 0.0f) + (Input.GetAxis("Move Backward") > 0.0f ? -1.0f : 0.0f);

            Vector3 forward = new Vector3(camera.Forward.x, 0.0f, camera.Forward.z).normalized;
            Vector3 right   = new Vector3(camera.Right.x, 0.0f, camera.Right.z).normalized;

            if (!MathUtils.IsZero(movementX) || !MathUtils.IsZero(movementZ))
            {
                controller.CurrentDirection = ((forward * movementZ) + (right * movementX)).normalized;
                controller.CurrentMagnitude = Input.GetKey(KeyCode.LeftShift) ? 1.5f : 1.0f;
            }
            else
            {
                controller.CurrentMagnitude = 0.0f;
            }

            controller.Jump = Input.GetAxis("Jump") > 0.0f;
        }
示例#4
0
 /// <summary>
 /// Handles all camera related input.
 /// </summary>
 /// <param name="camera"></param>
 /// <returns></returns>
 private bool ProcessCameraInput(ref CameraFollowComponent camera)
 {
     return(ProcessCameraZoom(ref camera) ||
            ProcessCameraYawPitch(ref camera));
 }