I'm implementing steering how to clamp rotation?

how to limit rotation with clamp?
when turn left

k -= 0.02;
let rotZ = pc.math.clamp(k, -0.5, 0);
wheelFR.rotateLocal(0, 0, rotZ);
wheelFL.rotateLocal(0, 0, rotZ);

and when turn right increasing k by 0.02
I think I hardly have result

I want to turn left so range 0, -0.5 and right so 0, 0.5

and also tried limiting with half of sinus, this makes limit but when reaches 0.5 value then decreases so don’t matches

If your range is -0.5 to 0.5 to set the steering of the wheels, you should really do something like:

if (turningLeft) {
    k -= 0.02;
}
if (turningRight) {
    k += 0.02;
}
let rotZ = pc.math.clamp(k, -0.5, 0.5);

wheelFR.rotateLocal(0, 0, rotZ);
wheelFL.rotateLocal(0, 0, rotZ);
1 Like