Exemplo n.º 1
0
    void FixedUpdate()
    {
        var PlayerIsMoving       = rb.velocity.magnitude > thresholdSpeed; // Used to limit when player can rotate
        var ValidBreathDetected  = UserInput.isExhaling();
        var UserIsPressingButton = UserInput.isHoldingButtonDown();

        if (PlayerIsMoving)
        {
            pc.showAsInactive(); pc.stopRotating();
            cc.UpdateDirection();
        }
        else
        {
            pc.showAsActive();
            if (UserIsPressingButton)
            {
                pc.Rotate(); direction = pc.getDirection();
            }
            else
            {
                pc.stopRotating(); cc.UpdateDirection();
            }
        }

        if (ValidBreathDetected) // Move player
        {
            var convertedDirection = direction * (float)Math.PI / 180;
            var forceDirection     = new Vector3(speed * (float)Math.Sin(convertedDirection), 0.0f, speed * (float)Math.Cos(convertedDirection));
            rb.AddForce(forceDirection * speed);
        }
    }