Example #1
0
    void Update()
    {
        if (Time.timeScale == 0)
        {
            return;
        }

        float horizontalRotation = FakeControls.GetMouseX();

        transform.Rotate(0.0f, horizontalRotation * rotationSpeed, 0.0f);

        verticalRotation -= FakeControls.GetMouseY();
        verticalRotation  = Mathf.Clamp(verticalRotation, -verticalRotationLimit, verticalRotationLimit);
        Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation * rotationSpeed, 0.0f, 0.0f);

        Vector3 movement = new Vector3(FakeControls.GetHorizontal(), 0.0f, FakeControls.GetVertical());

        controller.Move(new Vector3(0.0f, -gravity * Time.deltaTime, 0.0f));
        controller.Move(transform.TransformDirection(movement) * Time.deltaTime * speed);
    }
Example #2
0
    private void Update()
    {
        if (Time.timeScale == 0)
        {
            return;
        }

        float bobAmount = Mathf.Abs(FakeControls.GetVertical()) + Mathf.Abs(FakeControls.GetHorizontal());

        bobAmount = Mathf.Clamp01(bobAmount);

        bobTimer += maxHeadBobSpeed * bobAmount;
        if (bobTimer > 2 * Mathf.PI)
        {
            bobTimer -= 2 * Mathf.PI;
        }

        if (bobAmount == 0)
        {
            if (bobTimer < -0.05f)
            {
                bobTimer += maxHeadBobSpeed * Time.deltaTime;
            }
            else if (bobTimer > 0.05f)
            {
                bobTimer -= maxHeadBobSpeed * Time.deltaTime;
            }
            else
            {
                bobTimer = 0.0f;
            }
        }

        Vector3 newPos = originalPos + Vector3.up * Mathf.Sin(bobTimer) * maxHeadOffset;;

        transform.localPosition = newPos;
    }