I’m having a hard time trying to figure out a solution for something that seems like it should be simple lol anyways this is it:
currently I have those on floor and on wall checks in the physics process of the player script which make it so that when true the jump count is zero allowing for normal jumps from the floor and also walls, then I have a seperate script for each state the player transitions to.
The only places I do jump_count += 1 is when I enter the jump state and also the fall state, (if previous state was not jump). Its added in the fall state as well because I didn’t want the player to be able to jump midair after falling off a ledge, and with the ability to do multiple jumps I think its more intuitive in my case to have your first jump taken away if you fall off a ledge since in my game jumping midair will only be allowed technically if you acquire an item that will allow multiple jumps.
The problem came when I had to fix a bug which allowed midair jumps sometimes and I ended up rewriting some code which works better now except I realized my system for changing the jump count was pretty shaky. I tried adding one to the jump count if I was in air and not touching walls to try and remedy the bug but quickly realized that I was doing that in physics process which means that it added one every frame making huge and innacurate numbers. I know my amateur skills are showing lol but I appreciate all the help either way
This is good because then I would use what your saying and make the code do this:
if !is_on_floor():
If jump_count !> 1: jump_count += 1
Although sorry i forgot to mention the reason i have jump count and not a boolean is so that I can allow more than one jump, so I’m guessing all I have to do then is this:
if !is_on_floor():
if jump_count !> max_jumps: jump_count +=1
But then wont that still have the same problem as before it will keep adding to the jump counter until the max jump integer. Sorry im still beginner and this one is confusing me.
Currently i add one jump when I enter the jump state and also if I fell off a ledge and the last state was anything but jump because then without that check i end up with two on the jump count when it should be one, thanks again
Sorry, I didn’t have quite the grasp of what exactly you wanted. Yeah, there are many ways to deal with this but but the simplest one looking at what seems to be your code is to lock things with a well placed boolean. Something like this:
var canCount : bool = true
if !is_on_floor() && canCount:
if jump_count !> max_jumps: jump_count +=1
canCount = false
However you will need to make canCount truth for the next time you want to raise the counter. For example as part of your “Jump” function. However that begs the question on why aren’t you just raising the jumpCount on your “Jump” function? A jump function only need to happens once. I’m assuming you have a jump function here, however I don’t know.
Lol yes sorry, I realize now my original post is lacking clarity, I’ll edit it for future readers in case they see this. But yes, currently I have those on floor and on wall checks in the physics process of the player script and then I have a seperate script for each state.
The only places I do jump_count += 1 is when I enter the jump state and also the fall state, (if previous state was not jump). Its added in the fall state as well because I didn’t want the player to be able to jump midair after falling off a ledge, and with the ability to do multiple jumps I think its more intuitive in my case to have your first jump taken away if you fall off a ledge since in my game jumping midair will only be allowed technically if you acquire an item that will allow multiple jumps.
So I’m home now and will try to experiment with this can_count boolean and see if I have any luck. Thanks again
Alright so I tested the game while continuously printing the jump count and I think I fixed it.
I didn’t end up using a can_count variable but the suggestion made me go back and check all of the places I was setting can_jump and jump_count.
Turns out all I needed to do was move some of them around and also add a if jump_count != 0 check in there and its all good. Although I am still doubtful that it is bug free, that will be for another time, when I do discover any, thank you.