public void UpdateWeaponState(PlayerInput.Input input)
        {
            PrimaryWeapon.UpdateState();

            if (input.Shoot)
            {
                PrimaryWeapon.TryFire();
            }
            else
            {
                PrimaryWeapon._isTriggerReleased = true;
            }

            if (input.Aim)
            {
                PrimaryWeapon.Aim();
            }
            else if (input.Reload)
            {
                PrimaryWeapon.BeginReload();
            }
            else if (input.Melee)
            {
                //Melee();
            }

            if (input.Shift)
            {
                ChangeWeapons();
            }
        }
        public void UpdateMovementState(PlayerState state, PlayerInput.Input input)
        {
            //Debug.Log("Moving. Vertical: " + input.Vertical + " Horizontal: " + input.Horizontal + "state: " + state.IsCrouched);

            if (grounded)
            {
                // Calculate how fast we should be moving
                Vector3 targetVelocity = new Vector3(input.Horizontal, 0, input.Vertical);
                targetVelocity  = transform.TransformDirection(targetVelocity);
                targetVelocity *= speed;

                // Apply a force that attempts to reach our target velocity
                Vector3 velocity       = GetComponent <Rigidbody>().velocity;
                Vector3 velocityChange = (targetVelocity - velocity);
                velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
                velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
                velocityChange.y = 0;
                GetComponent <Rigidbody>().AddForce(velocityChange, ForceMode.VelocityChange);
                //transform.position += targetVelocity;

                // Jump
                if (canJump && input.Jump)
                {
                    GetComponent <Rigidbody>().velocity = new Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
                }
            }

            // We apply gravity manually for more tuning control
            GetComponent <Rigidbody>().AddForce(new Vector3(0, -gravity * GetComponent <Rigidbody>().mass, 0));

            grounded = false;
        }
Exemple #3
0
        public void UpdateLookState(PlayerInput.Input input)
        {
            // Allow the script to clamp based on a desired target value.
            var targetOrientation          = Quaternion.Euler(targetDirection);
            var targetCharacterOrientation = Quaternion.Euler(targetCharacterDirection);

            // Get raw mouse input for a cleaner reading on more sensitive mice.
            var mouseDelta = new Vector2(input.VerticalLook, input.HorizontalLook);

            // Scale input against the sensitivity setting and multiply that against the smoothing value.
            mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity.x * smoothing.x, sensitivity.y * smoothing.y));

            // Interpolate mouse movement over time to apply smoothing delta.
            _smoothMouse.x = Mathf.Lerp(_smoothMouse.x, mouseDelta.x, 1f / smoothing.x);
            _smoothMouse.y = Mathf.Lerp(_smoothMouse.y, mouseDelta.y, 1f / smoothing.y);

            // Find the absolute mouse movement value from point zero.
            _mouseAbsolute += _smoothMouse;

            // Clamp and apply the local x value first, so as not to be affected by world transforms.
            if (clampInDegrees.x < 360)
            {
                _mouseAbsolute.x = Mathf.Clamp(_mouseAbsolute.x, -clampInDegrees.x * 0.5f, clampInDegrees.x * 0.5f);
            }

            var xRotation = Quaternion.AngleAxis(-_mouseAbsolute.y, targetOrientation * Vector3.right);

            cameraObject.localRotation = xRotation;

            // Then clamp and apply the global y value.
            if (clampInDegrees.y < 360)
            {
                _mouseAbsolute.y = Mathf.Clamp(_mouseAbsolute.y, -clampInDegrees.y * 0.5f, clampInDegrees.y * 0.5f);
            }

            cameraObject.localRotation *= targetOrientation;

            // If there's a character body that acts as a parent to the camera
            if (characterBody)
            {
                var yRotation = Quaternion.AngleAxis(_mouseAbsolute.x, characterBody.transform.up);
                characterBody.transform.localRotation  = yRotation;
                characterBody.transform.localRotation *= targetCharacterOrientation;
            }
            else
            {
                var yRotation = Quaternion.AngleAxis(_mouseAbsolute.x, cameraObject.InverseTransformDirection(Vector3.up));
                cameraObject.localRotation *= yRotation;
            }
        }
 public void UpdateVehicleState(PlayerInput.Input input)
 {
 }