I’m using a Character with a CharacterMovementComponent as my player in a game where the player can perform multiple jumps (limited by Max Jumps) before hitting the ground.
I’m able to detect when the player lands on an npc, and I want that to count as “hitting the ground” so they are able to jump again after bouncing off an npc’s head in order to chain jumps.
Problem is, using the CharacterMovementComponent, I see no way to reset the JumpCurrentCount back to 0 so the player can start jumping fresh.
JumpCurrentCount is a read only integer variable in Blueprint and I see no way to reset it, set it to 0, or have the character think it is back on ground for a frame from within Blueprint. My Character.h file is also read only, so it doesn’t appear that just changing that var to BlueprintReadWrite will work, and I’d rather not change a core header file anyways.
Any thoughts? I have the rest of my jump mechanics working well within the Movement Component setup but wasn’t expecting this to be an issue. Thanks in advance for your help!
I came up with a basic fix that works pretty well:
I set my NPC’s capsule collision to CanCharacterStepUpOn = (Owner)
After detecting that my Player has collided with an NPC near the player’s feet, I kill the NPC and call Jump() on my player
The result is that if I land on an enemy, it’ll count as “ground” for a frame, clearing my jump count, and the Jump() call will cause my player to bounce up. Then I can press jump again to double jump in the air, etc.
There are (literal) edge cases with this approach, if my method of detecting that the player landed on the enemy declares positive but the physics engine doesn’t let the player step on the enemy because the angle is slightly off, but I think that can be cleared up by either:
a.) Making sure the collision event has the same parameters as the character’s step angle
b.) (haven’t tried this yet) Doing a “Are you standing on this” check against the NPC before declaring a successful stomp
Use a variable integer to store # of jumps, if that # jumps isn’t exhausted and they (Is Falling), use (Launch Character), then add onto that # whenever the player jumps. If you want to cleanly reset it, this works really well.
I know this is years after, but since I search through this site looking for answers quite often, I’ll throw it out.
For anybody facing a similar problem, i found another solution, that can be executed anytime you want, not just when landing on an enemy, and it still uses the default jump system. You can add your default jump count to current jump count (this says how many times you have jumped) and set it as the new max jump count, then just set it back to default when you want to reset the max count (for example when you land from a wall run).
Hope this helps.