in my project I have to perform bicycle control, namely the player has a circular control joystick, by turning the joystick to the right the player pedals faster, therefore he goes faster, by
pedaling in the opposite direction the player slows down.the cyclist moves along only one trajectory, but when turning, the joystick goes either faster or slower. Please help, because I do not understand how to implement this, thank you in advance
public class Bike : MonoBehaviour
{
//How fast the player will accelerate
public float Speed = .25f;
//how fast the player will Go
public float MaxSpeed = 2.5f;
float CurrentSpeed;
private void Update()
{
float pedalspeed;
//GetAxis Ranges from -1 to 1, Vertical gets joystick axis, WS, And up and down arrow
//If joystick is all the way forward, Pedalspeed will = 1, meaing player is pedaling at full speed
pedalspeed = Input.GetAxis("Vertical");
CurrentSpeed =
Mathf.Clamp( //Clamps the Max speed so you can't go too fast
CurrentSpeed + ((Speed / 100) * Time.deltaTime) * pedalspeed, // Speed will slowly incress untill it hits max speed
-MaxSpeed, // Change this to 0 if you rather have the bike stop instead of reverse
MaxSpeed / 100
);
//Use currentspeed to move the bike
transform.position += Vector3.forward * CurrentSpeed;
}
}