• 🏆 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!

[Solved] [Math Problem] Implementing XY velocity to double jump

Status
Not open for further replies.
Level 1
Joined
Feb 12, 2017
Messages
7
HELP! I SUCK! 2 hours and I still can't figure it out!

So here's a sample trigger I have when the unit jumps from the ground:
  • 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
And this is the periodic trigger:
  • 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
What I want to do is to calculate the exact timing, and velocity, from where the starting jumping position to the target landing position.

Oh, also I know about this standard parabola equation already:
JASS:
function Parabola takes real height, real current, real max returns real
    return 4 * height * current * (max - current) / (max * max)
endfunction
But I decided not to use it cuz this doesn't quite work when I want the unit to jump without moving. Or the unit is just free falling (yes, I want gravity), due to the fact that it calculates the distance traveled.

I'm not exactly limited to just using my trigger I posted above (as I don't really know what I'm doing). If you know the math on how to do this better, PLEASE!

Just want to mention, I really, REALLY, suck at math! If you could just please give me the solution converted already to GUI/Jass/vJass script, or explain how without using fancy math words and symbols I would really appreciate it!!! I would prefer the former though, my head hurts already...
 
Level 1
Joined
Feb 12, 2017
Messages
7
Yay someone respond!
Sorry for that, English is not my first language. What I meant is having a unit jump from its position (starting) and landing exactly on the target point.
What's happening right now is that the jumping unit is landing early, or late (going over the max distance). It's because I fail to calculate the force, gravity, and the max distance from start point to land point.

I mean, the standard jumping system uses that vJass parabola I posted right? And it works perfectly. But the problem is it only calculates by distance traveled. Meaning it is only "faking" the gravity by calculating the distance from the starting point to the current moving (XY) position. What if I just want free fall, and not having XY velocity at all.
 

AGD

AGD

Level 16
Joined
Mar 29, 2016
Messages
688
I see.
What if I just want free fall, and not having XY velocity at all.
That generic equation above indeed encounters a problem in vertical scenarios, because of the division by 0. We usually solve this by making the xy-distance very small but non-zero.
So the parabola function becomes
JASS:
function Parabola takes real height, real current, real max returns real
    set max = max + 0.00001 // <--
    return 4 * height * current * (max - current) / (max * max)
endfunction
But you mentioned it having problems due to 'faking gravity', so it seems you want the velocity to depend on some 'gravity acceleration variable' and have the jump duration depend on it, rather than specifying the jump duration. Is this right? If so, it would be easiest to have 2 variables to keep track of the z and xy velocities separately.

  • Set ZVelocity = 100.00
  • Set XYVelocity = 150.00
You can also get the XYVelocity and ZVelocity from a single initial Velocity with magnitude and direction, like:
  • Set Velocity = 200.00
  • Set XYAngle = 0.00
  • Set ZAngle = 45.00
  • -----------------
  • Set XYVelocity = (Velocity)*(Sin(ZAngle))
  • Set ZVelocity = (Velocity)*(Cos(ZAngle))
Then simply increment the z-velocity by the acceleration due to gravity periodically on your periodic trigger. The xy-velocity simply remains constant.

Variables
  • Set GRAVITY = -9.81
  • Set PERIODIC_TIMEOUT = 0.03
Periodic Trigger
  • Set ZVelocity = ZVelocity + GRAVITY*PERIODIC_TIMEOUT
  • Set Height = (Height of Unit) + ZVelocity
  • Animation - Change Unit's height to Height at rate 0.00
 
Level 1
Joined
Feb 12, 2017
Messages
7
But you mentioned it having problems due to 'faking gravity', so it seems you want the velocity to depend on some 'gravity acceleration variable' and have the jump duration depend on it, rather than specifying the jump duration. Is this right? If so, it would be easiest to have 2 variables to keep track of the z and xy velocities separately.
YES! This is EXACTLY it! Thank you very much! I was getting desperate, brainstormed this for a total of 5 hours yesterday!
I'll give you credits once I finish my project! If ever, as I'm just getting back to modding!

Imma try implementing this and mark this thread as SOLVED if I don't encounter any issues!
Once again thank you!
 
Level 1
Joined
Feb 12, 2017
Messages
7
So it works, but now I'm back from the start.
I'm sorry, but how do I calculate the velocity from point A to B for the unit land? I tried solving/guessing again but to no avail...
 

AGD

AGD

Level 16
Joined
Mar 29, 2016
Messages
688
For even ground - meaning the source and target elevations are equal, you can use this function.
JASS:
function GetProjectileVelocity takes real pitchAngle, real maxRange, real gravity returns real
    return SquareRoot((gravity*maxRange)/Sin(2.*pitchAngle))
endfunction
Basically, you need both pitchAngle (the ZAngle) and maxRange (the xy-distance), in order to know the needed initial velocity. The angle you pass here should be measured in degrees.
 
Level 1
Joined
Feb 12, 2017
Messages
7
ALRIGGGHT!! Finally got it working perfectly!
Although I want to point out, just in case, that the gravity on GetProjectileVelocity function should ALWAYS be a positive number. Cuz it was not working at first, but then I realized we set the constant world GRAVITY to -9.81, and of course this will return NaN which is a NO NO. I just changed it to -gravity to invert it to positive.

This is now SOLVED! Thank you very much for your time AGD!
 

AGD

AGD

Level 16
Joined
Mar 29, 2016
Messages
688
Although I want to point out, just in case, that the gravity on GetProjectileVelocity function should ALWAYS be a positive number. Cuz it was not working at first, but then I realized we set the constant world GRAVITY to -9.81, and of course this will return NaN which is a NO NO. I just changed it to -gravity to invert it to positive.
Right. Glad it's working now =).
 
Status
Not open for further replies.
Top