Is the check if variable is certain value creating performance hit?
So, here is my code in Unity (I run it in Update):
This code is like a speed limiter for a ball in a game.
Basically, it's doing this: If the ball is flying in the air and going really fast, it turns down the 'air boost' to slow it down a bit. The faster it's going in the air, the more it reduces this boost. But if the ball is on the ground or moving slowly, the 'air boost' goes back to normal.
So, my question is:
This code is like a speed limiter for a ball in a game.
Basically, it's doing this: If the ball is flying in the air and going really fast, it turns down the 'air boost' to slow it down a bit. The faster it's going in the air, the more it reduces this boost. But if the ball is on the ground or moving slowly, the 'air boost' goes back to normal.
So, my question is:
- Is it a good way to change a value and then bounce back to the original value?
- (MAIN) I'm running this in Update function, meaning 60 times per second. I'm worried that I'm going to set addForceSpeedAir to originalAddForceSpeedAir each time the if statement goes to else. So, it's going to set it once, and then each second 60 times. But, in my view only way to escape this is to Check with
else if addForceSpeedAir == originalAddForceSpeedAir, but then again, I'll be checking 60 times a second if a value is something, which also sounds pointless.
Is there any way to escape this?