Small update tonight to implement three new boot sockets. These new sockets allow the player to float in the air after reaching the apex of the jump, if the jump button is still held. The amount of float time is static (20 frames), and that time is doubled for the Float +2 socket and tripled for the Float + 3 socket.
As with the “looking up” and “looking down” states, the floating state does not currently have animation sprites. Therefore, I just have the word “floating” display on the player for testing purposes.
Floating could have been implemented many ways, but I like booleans so I created an isFloating bool to signify if the player is floating. I also have an integer tracking the amount of float time. When the player jumps, if a Float socket is equipped then the float time integer gets set to the number of frames that the player should float based on which Float socket is equipped. When the player’s jump acceleration reaches zero, then the isFloating value gets set to true if the float counter is greater than zero. Otherwise, the player will start falling. On each update, the float counter is decremented until it reaches zero. At that time, the player will start falling as they normally would after reaching the jump apex, and the isFloating bool gets set to false. The separate bool and integer variables may be slightly redundant, but I think it makes the code more readable. A future optimization could be to replace the bool variable with a function that returns true if the float time is greater than zero and false otherwise.
I also slightly modified the crouching code. If the player is walking and rolls the control stick to the down/forward position, then the player will walk and look down. From this state, if the player rolls the control stick completely down, then the player would still be looking down and standing (not crouching). This was to prevent the player from crouching when holding down and forward, when the player should be moving. In ResistorKit, I only have methods that fire when up, down, left, and right are pressed or released, so the crouching code was only fired when the down and pressed action was fired. The player is not allowed to crouch if the jumping, falling, or walking states are active. To fix this, in the code that causes the player to stop walking, I added code to set the player to the crouching state if the player is looking down. This behavior is slightly different from other classic platformer games that also don’t set the player to crouching when rolling from foward to down, but I feel that my new way feels more natural. With the old way, the only way to crouch was to press directly down from a standing position which feels clunky.
Floating was a fairly simple mechanic to add in about two hours. I’m hoping to get back to character modeling, but there is a huge learning curve for me to complete that task.