This is a bit lengthy and has no TL;DR…
Assuming you are in the OnTick event for this, assuming you use blueprints, and assuming you are still using a variation of character movement.
First, you have an “is falling” value that is automatically handled by the engine for every pawn/actor or anything that has a movement component really. Probably (not sure) also paper2D. This is probably irrelevant, however it’s worth mentioning because of how it works.
Constant line-trace from capsule end downwards to “find the floor” and trigger the Boolean if the floor is not at a range of nearly 1.
Second thing to note, Physics. You need or usually want to apply a mathematical movement interpretation.
There are many variation on how to do things. A well thought out system goes a long way to making game-play cooler - for instance slipper surfaces. silent surfaces, so on.
Consider the fact that the characters are always sliding around and just seem to be walking 2d or 3d doesn’t change this. The capsule is locked onto the floor or whatever it hits, it can’t “float” mid air with every step.
Essentially, go back to newton’s second law:
An object’s acceleration is the result of all forces acting on the object - this includes wind resistance - which since the item is sliding is basically ground attrition - and gravity.
So, Force = Mass * Acceleration per the law.
Ergo Acceleration = Force / Mass (per basic algebra).
The weight of the object is the Mass x Gravity - not very relevant if you approximate your movement system, but good to know.
The mass can be used to calculate the Friction on a given surface.
But what is Force within the equation above?
Force = Force Apparent - Force Friction
All that said, A character is not really a billiard ball - right?
So in order to come to a stop we can apply a liberal amount of counter-force to the movement to cause the moving object to stop in a slightly more “natural” way.
We can call that our “break force” or “Breaking Deceleration Walking” within the movement controller.
Assuming that clears up the physics, you should now be able to implement a very basic version of an actual mathematical formula that allows you to change the current acceleration more dynamically.
You can put a MAX to the overall force, which will cause the speed to max out as well. you can apply the same amount of force over time to reach said speed, and all you have to do is tweak the numbers to taste.
You can Burst like described by also applying a different amount of force (double the normal?).
You can also scale the amount of force initially to have the same effect you described above - purely based on velocity and accumulated momentum (total applied force).
Essentially you know that if your force is going down you won’t apply double the force, if your force is going up you can x2 it a couple times to reach the max faster.
Now back to the Jumping stuff.
I would actually only allow the second jump if in X proximity to the wall/edge/floor, where X is both the variable of how close you are, and the X axis for distance assuming the unreal Right Handed coordinate system applies to paper2d as well and that Y is in this case depth where Z is Vertical.
As a way of checking the vertical position I would use something like this:
Store the previous value of the variable - OLD Variable = Variable THEN set Variable = value.You can then check the delta between the 2 ( Old - Variable).
This tells you 2 things in 2D space; the direction: an increase or decrease in delta is essentially “which way am I going”? AND the distance from the previous position over the frame.
Worked out example:
Assume that the floor is at X 330 and Z10
Assume the jump is moving the same direction but ends up short at X 329 and Z10. Assume there is no floor so the character falls off the edge Mario style.
Per tick Current X - Previous X = X delta, Current Z - Previous Z = Z delta.
If Z delta is negative AND X delta is Positive (jumping towards target)
Merge the math:
if next frame Z is below floor level (Z = 10 AND Z Delta < 0) AND (X location < 330 AND location >310 AND X Delta > 0) THEN allow a double jump.
Hope that makes sense and that you can work out the exact math that makes it possible from the basic logic
The “time” you can actually ignore completely by the way. you can simply make the Z check be between 2 values instead of seeing if it’s the same as the floor.
Maybe in a Z > Z - grace AND Z < Z + grace fashion so you can easily manipulate your grace “period”.
Assuming you made use of proper physics as above your Mass/Gravity calculations will take care of the time dilation between the grace period and the floor level…