I want to make 4 functions for vehicle. Help me

I want to make 4 types of gears in the car.
The first is P, which means parking. When the gear is in P, the vehicle does not move when the accelerator is pressed.
The second is N. N means neutral. Even if you step on the accelerator, it doesn’t move forward, but if there is a car in the slope, it will roll along the slope.
The third is D. D means driving. With the gear set to D, the vehicle slowly moves forward without stepping on the accelerator. Slow starts at zero and has a maximum speed of 5 km/h.
The fourth is R. R stands for reverse. If you set the gear to R and step on the accelerator, you will go backwards instead of forwards.
When implementing this feature, the s-key on the keyboard is meaningless. Assign a new key to change gears and implement the brakes as a spacebar.
I want to implement it like this. But I’m wandering because I don’t know how to split the gears. I appreciate your help.

just make an enum and add a switch on the input

I think that’s how to separate the keys, but how should I implement the function??

so say the S-key adds a forward movement input lets say a value of 1, pass that input through a switch or select off enum, park/neutral could multiply the 10 so there is no forward value, reverse could 1-1 and drive could do nothing.

that should give you an idea

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.