Esempio n. 1
0
        private void HandleCharacterInput()
        {
            TPPlayerCharacterInputs characterInputs = new TPPlayerCharacterInputs()
            {
                MoveAxisForward = Input.GetAxisRaw(VerticalInput),
                MoveAxisRight   = Input.GetAxisRaw(HorizontalInput),
                CameraRotation  = mainCamera.transform.rotation,
            };

            characterController.SetInputs(ref characterInputs);
        }
        /// <summary>
        /// This is called every frame by MyPlayer in order to tell the character what its inputs are
        /// </summary>
        public void SetInputs(ref TPPlayerCharacterInputs inputs)
        {
            Vector3 moveInputVector = Vector3.ClampMagnitude(new Vector3(inputs.MoveAxisRight, 0f, inputs.MoveAxisForward), 1f);

            Vector3 cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.forward, Motor.CharacterUp).normalized;

            if (cameraPlanarDirection.sqrMagnitude == 0f)
            {
                cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.up, Motor.CharacterUp).normalized;
            }
            Quaternion cameraPlanarRotation = Quaternion.LookRotation(cameraPlanarDirection, Motor.CharacterUp);

            MoveInputVector = cameraPlanarRotation * moveInputVector;
            LookInputVector = cameraPlanarDirection;
        }