How to clamp distance of launch, while allowing further imput?

Hello!

I’ve run into an issue with a blueprint I am trying to work on. I am trying to set up the character’s jump so that while pressing only space bar, it acts normally, but while also pressing the W key (Here Input_MoveFWD) they will be launched horizontally a certain distance, to give the player control to a purely vertical, or horizontal jump.

I have run into two issues, however. The first is that I am trying to cause the distance traveled, rather than being the flat 1500 distance, to be determined by how long the W key (Input_MoveFWD) is held down. So holding it down for a mere second would give a shorter horizontal distance than holding it down for 5 seconds. However, any attempts I try only work when the key has been held down and -then- released, not actively while you are moving.

Secondarily, I want to clamp the distance traveled so there is a max float that can be reached. So instead of holding down w and going up to an infinite number, it would stop at 1500, for example. If anyone knows how to do this, help would be greatly appreciated. Thank you.

I would recommend a “Timeline” with a float track to determine the “max distance”. On pressed, start the timeline, and let it run for as long as you want it to take to reach “max” jump, so 3 seconds for example, on release, stop the timeline, use the output in whatever calculations you want for jumping distance. So your float track in the timeline would go from 0 ft, at 0 seconds of holding, to 1500 ft at 3 seconds of holding.

Unless I am mistaken, this system only works when you hold down and -then- release. It doesn’t work if you are already moving, or at least that is how it looks when I tried implementing it.

Your system confuses me. If “W” is move forward and “space” is jump, why would the duration the W key is held be what determines how far the jump is? Shouldn’t that be the space bar then? Either way a timeline will work for getting the “duration to distance” conversion perfectly based off how long a key is heels. Your issue seems to be more weird jumping logic than anything. Maybe describe better how you want your keys to work and if my initial understanding is correct…WHY you want the forward button to determine the jump not space bar? It just seems a little backwards to me.

Yes and no…It also doesn’t sound like a “jump” any more either. Hence the confusion. You are actually trying to script “flight” mechanics not “jump” mechanics. Unreal is set-up for “jump” which is a simple physics based calculation. When you press space bar it only ever affects vertical distance. If you hold down “W” the player moves forward up to the “max walk speed” then continues going that horizontal speed indefinitely as long as the “W” key is held. If you press space bar during the time you hold the “W” key you will indeed go the same distance each time because the space bar imparts a set vertical force to cause the “jump” and the current horizontal speed once you lift off the ground cannot change therefore by projectile physics the player will always travel in the same arc and land the same distance away from the jump point. My method of leaving “W” to be the forward movement and use a timeline on the length the space bar is held will allow you to “time” a jump and strength of that jump so long as you are running on the ground like normal jump mechanics. The longer the space bar is held before release the further the player “jumps” because it will directly correlate with the “force” added at the start of the jump. Once the jump occurs there is no way to change the projected landing point. So my method the ability to jump 10 ft vs 20 ft depends on how long you run while holding space bar before a release. This is a true “jump”. Flight mechanics allow you to change things “mid air”. If you want that then I suggest you use a different button NOT the “W” key since that is an “axis” value from (-1 to 1), it doesn’t do “in between” values, You need to separate the forward movement on the ground, from the jump, from the forward movement in the air. These are 3 separate types of movement.

So you want to press “W” start moving forward 5m/s, press space bar, fly up in the air (are we still moving forward or does that stop? are we hovering now?) while in air, press “W” hold for 2 seconds, move 10 ft forward? So we now get to use “W” again as if we are on the ground to move forward through the air based on duration of key down? Like how exactly is this all working?

The idea is that pressing space-bar only affects your vertical jump height. So for example, if you are simply wanting to jump over a small hurdle, you would just be pressing the space bar to go over it. Pressing -W- while in the middle of a jump would affect the horizontal distance traveled. From what I have seen, the base system in UE4 with the basic jump only propels you the distance of your movement speed when you are jumping. So when you are moving and press jump, assuming you have air control, you are moving at the same distance you would if you had just been walking.

What I am trying to do is give the user direct control over their horizontal distance. So for example, if you want to jump a five foot gap, you would hold W down for a second or two while in mid air and then release, and stop moving horizontally. But if you want to jump, say, a twenty foot gap, you would need to hold it longer.

Right now, the way it is set up you are simply launched a flat distance regardless of how long you have held the key down. This is a big problem if, for example, you are doing a tricky jump and want to hit a specific point. If the point you want is 10 feet away, but the distance for horizontal jump is set to 30, you will fly past the target.

Using the Timeline system requires you to hold down and -then release- the w key to actually start moving horizontally. What I am trying to get is that the second you hold the key down you start moving, and you stop moving forward when you release. So holding it down might move you say 5 feet per second, and at any point releasing it stops launching you and you start to fall. In addition, I am trying to limit the maximum distance that can be traveled. So rather than being able to jump 500 feet, it would stop at 20 or 30 feet regardless of how long you held it down past a certain point.

Does this make sense?

As the original screenshot showed, the jump is preformed and then seperately afterwards you are launched/add impulse (Launch Character and Add Impulse both seem to do the trick) -only- if you press the w key. If you only press space bar the jump works in the standard way. And right now in theory it works perfectly from the mechanic of being launched horizontally in the distance specified, but the issue comes in where the distance you are launched/ an impulse is added is fixed and is not affected by any other source.

Adding a time line only works if it is charged, as you have said that way would indeed work mechanically but functionally the goal is for the player to release the button early if they do not intend to be launched the maximum distance, instead of charging the button first and then releasing when it falls in the intended range of distance.

However, reading your explanation of the way the jump mechanic is utilized does give me two ideas I will try. Since as you said the jump is using ‘max walk speed’, increasing the max walk speed while in air could allow you to have a jump distance further than the distance traveled while walking, essentially acting as a horizontal jump if timed right, albeit not ideal.

Secondarily, a custom event could check on event tick if you are mid air and pressing the W key and launch you a small distance while held down, again not ideal though. I will report back with my findings, I hope this makes sense.

Honestly, at this point I think we are over-complicating something that really isn’t that complicated. If your screen shot set-up works and the only issue is you can’t change the “horizontal” launch distance (which I can see is the case since it is a hard-coded 1500) my suggestion remains to add a timeline with a float track. A timeline float track is not something that needs to be “charged” fully to be used. Maybe you misunderstand what the float track does. What I am saying is, once you are past the branch that says “can vault” add a timeline with a max length of whatever you would like the max “charge” as you call it to take to build up, then make 2 keys in the float track, the first at time 0, with a value of whatever you want the smallest launch velocity to be if someone just tapped the “W” button, and the second key at time “max charge” with a value of “max launch”. This will give you a continuously increasing float value for every point between 0 seconds and max charge time. Which is exactly what you want. On “release” of the “W” key, stop the timeline, and use the “output float value” as the launch distance for the “X velocity”. This will allow you to change the horizontal distance traveled based on length of time the “W” key is held down while in mid-air. I am not sure what the issue is with a timeline but I think it is your best bet. You can also use a timer, or do your own calculations with world time and delta time etc, I think there is even a function for “key down” or something that tells you how long a key is pressed, regardless you’re going to need some way to keep track of the “time” a key is held for any of this to work. Pick your poison.

I think you are quite right, I am overcomplicating the system. I’m going to try using your suggestions here and see if they work. Thank you for your responses and answers!

Self reply to follow up, neither of the following possibilities appear to be functional.