• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] [Solved] Double Jump ...

Status
Not open for further replies.
Level 15
Joined
Oct 29, 2012
Messages
1,474
Hello.

Well, I've been making a Jump system for some mini-game. But I faced some huge obstacle, besides I am bad at Maths.

Now I know I am making no mistakes in the first Jump System. But Seriously how can I make a second mid-air Jump so the player will jump again from the point and height he is at now ?!

This is an example picture of how I want the mid-air jump (Blue graph is the Jump Function, the red one is the mid-air one), I want something like (Move from the blue to the red) smoothly.

t3sztGw.png


I tried to make a Jump System, and also tried to add the Double-Jump thing, but I'd better not show how I had it done, it's a shame that it never works. I just want it to look exactly like the one in XANID's map, unfortunately it's written in vJASS :/... the jump is executed under the formula :

Yet I have no idea how to move from the normal jump formula into the double-jump one lol, the unit always returns onto the ground everytime I executed the Jump once again. (Remember I turned off the normal jump formula and executed the double-jump, it didn't work since I don't even know how to move between formulas).

JumpFormula
  • Events
    • Time - Periodic Event 0.03
  • Conditions
    • Jump_Executed = true
  • Actions
    • Set Time_Variable = (Time_Variable + 0.03)
    • Set Player_Height = ( - [squareroot(MAXHeight) - Time_Variable]² + MAXHeight )
    • Animation - Change Footman's Height to Player_Height at rate 0.00
Any math helpers ?

Thanks, and +rep+credits.
 
Last edited:
Level 22
Joined
Feb 6, 2014
Messages
2,466
Here's a detailed explanation on the solution to your problem.

I will derive the equation you will used as well for you to understand
a = dv/dt and v = dy/dt from Physics and using common sense.
and variables are
t1 = initial time, assumed 0, t2 = final time
v1 = initial velocity, v2 = final velocity
a = constant = -9.8 m/s2
then dy = vdt -> (y2-y1) = v(t2 - t1)
thus y2 = y1 + v(t22-t1)
a = dv/dt -> (v2-v1) = a(t2 - t1)
v2 = v1 + a(t2) but v = dy/dt
dy2/dt = v1 + at2
y2 = v1t + 0.5at22 + y1 this is now the formula you used to represent the height of the unit in terms of time and initial velocity. Feel free to choose what you think will result to most realistic acceleration but make sure it is less than zero (negative).

Now if a unit jumps initially from ground, y1 (initial height) = 0, just set v1 = any arbitrary positive value and you need to store that.
I simplified y2 -> y, t2 -> t in the equation below
Let's say the the unit jumps with initial velocity of 100 units per second, store that initial velocity to a variable
  • set v1 = 100
y = 100*t + 0.5(-50)(t2) + y1 is the equation
Points (height y, time t) of jumping:
(going up)
y = 100*0 + 0.5(-50)(02) + 0 = 0
y = 100*0.1 + 0.5(-50)(0.12) + 0 = 9.75
y = 100*0.2 + 0.5(-50)(0.22) + 0 = 19
y = 100*0.3 + 0.5(-50)(0.32) + 0 = 27.75
(going down, say t = 2.5)
y = 100*2.4 + 0.5(-50)(2.42) + 0 = 96
y = 100*2.5 + 0.5(-50)(2.52) + 0 = 93.75
At this point, the unit jumps mid air (exactly at t = 2.5), then recompute the current velocity
v2 = v1 + a(t2) = 100 + -50*2.5 = -25 then
add a new velocity to the current velocity, let's say 100 again
at this point,
  • set v1 = -25 + 100
and your new height equation will be and you need to reset time = 0
y = 75*t + 0.5(-50)(t2 + 93.75
y = 75*0.1 + 0.5(-50)(0.12) + 93.75 = 101
y = 75*0.3 + 0.5(-50)(0.32) + 93.75 = 114
y = 75*1 + 0.5(-50)(12) + 93.75 = 143.75
So noticed that the new height begins to rise again and eventually will fall down
y = 75*3.5 + 0.5(-50)(3.52) + 93.75 = 50

TL;DR your periodic trigger will be something like this
  • Set Player_Height = InitialVelocity*Time_Variable + 0.5*(Acceleration_Variable)*(Time_Variable*Time_Variable) + InitialHeight
  • Animation - Change Footman's Height to Player_Height at rate 0.00
When unit jumps from ground, any number will do and that number will dictate the jump magnitude
  • Set InitialVelocity = 100
  • Set InitialHeight = 0
when a unit jumps from mid air
  • Set InitialVelocity = 2*InitialVelocty + (Acceleration_Variable)*(Time_Variable)
  • Set InitialHeight = Player_Height
Note, you might wanna make that MUI using unit indexer with custom values as array index like
Time_Variabe[], Player_Height[]
Or use a Hashtable or struct per jump instance.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Double jump....
I assume that when you have one jump, you restrict the user to jump when it is in mid-air.
Remove that restriction and your jump should work... at least if the approach would have been right.

Just re-apply the jump that you have but start with a different (the current) flying height.
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
@Flux : Brilliant, I rebuilt my Jump's system (I will Give Credits to you) and its' working good.

@Dr. Super Good : Well, I think Flux' solution does that.

@Wielol : Well, that was actually the problem of the 'never-double-jump-executing' , but yet when It started to work, it looked @{é/! , (The reason was my high Math Knowledge xD).


Thanks to the three of you. FIXED. +rep for everyone.
 
Status
Not open for further replies.
Top