Example #1
0
    private void FixedUpdate()
    {
        // Read the inputs.
        if (Input.GetKey(KeyCode.Escape))
        {
            pauseMenu.InitPauseMenuUI();
            return;
        }
        bool  crouch    = Input.GetKey(KeyCode.S);
        bool  lookingUp = Input.GetKey(KeyCode.W);
        float h         = CrossPlatformInputManager.GetAxis("Horizontal");

        // Pass all parameters to the character control script.
        m_Character.Move(h, crouch, m_Jump, lookingUp);
        m_Jump = false;
    }
Example #2
0
    void Update()
    {
        if (controller.collisions.above || controller.collisions.below)
        {
            velocity.y = 0;
        }

        Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

        if (Input.GetKeyDown(KeyCode.W) && controller.collisions.below)
        {
            velocity.y = jumpVelocity;
        }

        float targetVelocityX = input.x * moveSpeed;

        velocity.x  = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below)?acclerationTimeGrounded:acclerationTimeAirborne);
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }