My problem now is checking when the player’s throttle has reached these key thresholds. I’ve tried stuff like:
if (throttle == maxThrottle/4)
{
//do stuff
}
But it’s not reliable. The throttle values are floats and I’m using gamepad analog triggers to change their values, so often times throttle never equals maxThrottle/4.
What is the proper way to check the throttle/maxThrottle, and then get some kind of true/false state I can use to trigger my camera shake?
You could check if the step changed (up or down) with something like this:
private int oldThrottleStep;
void Update() { // or some other method probably
int step = (int)Mathf.Floor(throttle / (maxThrottle/4)); // I think floor is even unnecessary
if (step > oldThrottleStep) {
// increased one step: shake it!
} else if (step < oldThrottleStep) {
// decreased one step: probably play some sound
}
oldThrottleStep = step;
}