Character Thrust - GetKeyDown

I was having a bit of a problem with my character’s thrust, because I wanted to modify things so that thrusting would only be detected when the player presses the key down. For a while I was just stuck because Unity only seemed to detect every odd few key presses and I couldn’t figure out why.

What I’ve learned from some simple console outputs is that FixedUpdate (which I am using as it relates to physics) doesn’t seem to respond well to the Input class, which is likely only meant for Update() - (isn’t as noticeable on a simple GetKey() - likely because that holds a broader range of states). The way I understand it, it has to do with the different timings of the function calls (“one per frame” vs “50 times per second”).

c# - Unity Input.GetKeyDown(KeyCode.Space) not detecting key Press - Stack Overflow

How I have overridden that for now is by checking for “key pressed” state in update while updating a Boolean and then resetting the Boolean in FixedUpdate() once the forces have been applied (as suggested in the link above) – which works visually (and at least I can’t press a space key 50 times per second, and so for me mechanically as well), but does seem like a bit of a patchwork solution.

Privacy & Terms