Ejemplo n.º 1
0
        protected override void InputUpdate()
        {
            UpdateSmoothingValues();

            float turn    = Input.GetAxis("Horizontal");
            float forward = Input.GetAxis("Vertical");

            // Get the jump input
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (mechController.Grounded)
                {
                    mechController.Jump();
                }
                else
                {
                    mechController.ActivateJetpack();
                }
            }
            if (Input.GetKeyUp(KeyCode.Space))
            {
                mechController.DeactivateJetpack();
            }

            mechController.LookRotationAmounts(new Vector3(rotationInputValues.x, rotationInputValues.y * (invertMouseVertical ? -1 : 1), rotationInputValues.z));

            mechController.SetRotationInputs(new Vector3(0, turn, 0));

            mechController.SetReversing(forward < -0.01f);

            //mechController.LookRotate(-20 * Time.deltaTime, 0);

            //mechController.Rotate(20 * Time.deltaTime);

            movementInputValues = forward * maxMovementInput * Vector3.forward;
            mechController.SetMovementInputs(movementInputValues);

            mechController.SetRunning(Input.GetKey(KeyCode.LeftShift));
        }
Ejemplo n.º 2
0
        protected override void InputUpdate()
        {
            UpdateSmoothingValues();

            // Get the movement input
            float forward = Input.GetAxis("Vertical");
            float right   = Input.GetAxis("Horizontal");

            // Get the jump input
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (mechController.Grounded)
                {
                    mechController.Jump();
                }
                else
                {
                    mechController.ActivateJetpack();
                }
            }
            if (Input.GetKeyUp(KeyCode.Space))
            {
                mechController.DeactivateJetpack();
            }

            float mouseX = (Input.GetAxis("Mouse X") / Screen.width) * 1000;
            float mouseY = (Input.GetAxis("Mouse Y") / Screen.width) * 1000;

            float valX = Mathf.Lerp(lastMouseX, lookRotationSpeed * mouseX * Time.deltaTime, lookLerp);
            float valY = Mathf.Lerp(lastMouseY, lookRotationSpeed * mouseY * Time.deltaTime, lookLerp);

            mechController.LookRotationAmounts(new Vector3(valX, valY * (invertMouseVertical ? -1 : 1), 0));

            // Rotate the mech according to the look controller
            Vector3 movementInputs = new Vector3(right, 0f, forward);

            mechController.SetRunning(Input.GetKey(KeyCode.LeftShift));

            movementInputs     = Vector3.Lerp(lastMovementInputs, movementInputs, lerpSpeed * Time.deltaTime);
            lastMovementInputs = movementInputs;

            bool reversing = movementInputs.z < -0.01f;

            mechController.SetReversing(reversing);

            Vector3 worldMovementDirection = mechController.lookController.HorizontalPivot.TransformDirection(movementInputs).normalized;


            Vector3 localMovementDirection = mechController.transform.InverseTransformDirection(worldMovementDirection);

            mechController.SetMovementInputs(localMovementDirection * movementInputs.magnitude);

            float turnAmount = 0;

            if (movementInputs.magnitude > 0.01f)
            {
                Vector3 localLegsTargetDirection = localMovementDirection;
                if (reversing)
                {
                    localLegsTargetDirection *= -1;
                }

                Debug.DrawLine(mechController.transform.position, mechController.transform.position + localLegsTargetDirection * 50, Color.red);


                turnAmount = Mathf.Atan2(localLegsTargetDirection.x, localLegsTargetDirection.z) * 10;
            }

            mechController.SetRotationInputs(new Vector3(0f, turnAmount, 0f));

            lastMouseX = valX;
            lastMouseY = valY;
        }