I've been trying to learn with Firebelly's tutorial for 2d platformers and wanted to add a bit of my own into the code
i want maxHorizontal speed to double only while player is in the air because i've managed to "make it work" with an if statement but as you can imagine it keeps adding speed every time jump is pressed.
Need help with while statement
- Edited
- Best Answerset by Romannnnn
Romannnnn The _process()
function gets automatically executed each frame, incessantly, 60 times per second. Doing a while loop inside it to test for a state persistency across multiple frames makes no sense.
Instead, you need to determine if the player is on floor or in the air at every individual frame by calling is_on_floor()
, and then set the max horizontal speed according to its true/false return value.
Btw While
is not a keyword in GDScript, whereas while
is. The language is case-sensitive.
xyz thanks, i added that to the if statement at lines 24/25 and it works well