My intention is to have forward and back motion to be hover while having the space bar controlling the throttling above the hover speed, or in other words, to climb.
The problem I am having is that when I throttle up while pressing forward, then let go, the helicopter continues to accelerate upwards like the throttle is still pressed.
I am still very new to coding and I know I am doing something fundamentally wrong with with the embedded if statement or my overall logic. Any help would be greatly appreciated.
I have suggested this to you before, and its something you should really consider, especially for keys already mapped. The GetAxis function is generally a better option for control to getkey in my experience. get key is great for turning stuff on and off or maybe for things like hotkeys, not so much for direct control.
What I suspect is happening is that it continues to think space is being pressed because it was the last button pressed, that combined with holding it down (safe assumption?). What happens when you press a different button after you release space?
on line 33
I would change: if (Input.GetKey(“space”))
to: if(Input.GetAxis(“Jump”)>0)
Also, you can change, add, and remove axis assignments and settings from the project input settings: Edit>Project Settings>Input (it will show up in your inspector). Increase the number at the top (the one to the right of “Size”) to add more axises…axisies…axies…whatever the plural is. lol
EDIT: Where is this code? Is this the only place that checks Input.GetKey(“space”)?
It was the only place that checks Input.GetKey(“space”), but now its Input.GetAxis(“Throttle”)>0, with thottle defined in the input manager, as per your suggestion.