Пример #1
0
    public void Move(float p_movement, float p_rotation)
    {
        if (jump)
        {
            if (groundCheck.OnGround)
            {
                //Jumping Audio
                playerAudioScript.PlayAudioRandom(0);

                // The new Jump!
                rbPlayer.velocity = new Vector2(rbPlayer.velocity.x, 4f);
                rbWheel.velocity  = new Vector2(rbWheel.velocity.x, 4f);

                jump = false;
                groundCheck.OnGround = false;
            }
            else
            {
                jump = false;
            }
        }

        // Movement
        //SmoothDamp is used to make the movement transition smoothly between directions
        currentMovementSpeed = wheel.jointSpeed;
        currentMotorSpeed    = Mathf.SmoothDamp(currentMovementSpeed, p_movement * maxSpeed, ref currentSmoothVelocity, 0.8f);
        currentMotorSpeed    = Mathf.Clamp(currentMotorSpeed, -maxSpeed, maxSpeed);
        JointMotor2D motor = new JointMotor2D {
            motorSpeed = currentMotorSpeed, maxMotorTorque = 10000
        };

        wheel.motor = motor;

        // Cycling Audio
        playerAudioScript.AudioModify(wheel.jointSpeed, maxSpeed, 1);

        if (p_movement == 0f)
        {
            wheel.useMotor = false;
        }
        else
        {
            wheel.useMotor = true;
        }

        rbPlayer.AddTorque(-p_rotation * rotationSpeed * Time.fixedDeltaTime * 10f);
    }