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

Math Help

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
I want a formula that changes acceleration. At a velocity of X I want the velocity to decrease to 0 in exactly X seconds, with a distance of X. So the acceleration will increase over time to make the velocity 0 within X seconds and at a distance of X.
Are you sure you want velocity, time and distance of the deceleration part to be the same? For low values it would look and the unit would barely move and for high values the unit will take forever to stop, doing so very slowly.

If you meant that they are separate variables...

You start from a constant speed X and time 0 (if not 0, then apply appropriate offset).
The time over which it should reach 0 speed is Y.
The distance over which it should reach 0 speed is Z.

The double integral of acceleration between time 0 and time Y is Z.
The speed, X, is the constant of integration of the integral of acceleration.
The integral of acceleration between time 0 and time Y factoring in X is 0.

As you might be able to guess, this is not an easy problem to solve since you have to find an acceleration formula such that its integral between 0 and time Y satisfies an equation while its double integral between 0 and time Y satisfies another.

integrate2(Acceleration, Y, 0) + Y * X = Z
integrate1(Acceleration, Y, 0) + X = 0

integrate2(Acceleration, Y, 0) = Z - Y * X
integrate1(Acceleration, Y, 0) = -X

Assuming linear acceleration...
integrate1x(k, Y, 0) -> kx using x[Y, 0] = Yk - 0k = Yk
integrate2x(k, Y, 0) -> kx^2/2 using x[Y, 0] = Y^2k/2 - 0k = Y^2k/2

Y^2k/2 = Z - Y * X
Yk = -X

I do not think a value of k exists so linear acceleration is out.

Assuming quadratic acceleration...
integrate1x(kx + l, Y, 0) -> kx^2/2 + lx using x[Y, 0] = kY^2/2 + lY
integrate2x(kx + l, Y, 0) -> kx^3/6 + lx^2/2 using x[Y, 0] = kY^3/6 + lY^2/2

kY^3/6 + lY^2/2 = Z - Y * X
kY^2/2 + lY = -X

This might be solvable? I am not sure.
 
Level 11
Joined
Aug 6, 2009
Messages
697
I do not understand what you did.
I am unsure what the variables mean, and which ones are constants.
Can you clarify, and walk me through, like I am a new born child?
Maybe I accidentally sent you on a wild goose chase, and for that, I am sorry for wasting your time.

I made a little picture to show what I want.
I want the unit to travel on the Z axis, or flying height.
I want it to reach 500 height at an initial offset which is being affected by acceleration to try and emulate gravity.
Once it reaches 500 height, I want it to come back down to the height where it started.

WhatIWant.png
 
Level 11
Joined
Aug 6, 2009
Messages
697
Assuming launch velocity is variable and times are constant then you could use a quadratic.

Y = c * X * (X - 2)

When X is 1, Y is Z

Z = c * 1 * (1 - 2)
Z = -c
c = -Z

Y = -Z * X * (X - 2)

Plotting for Z is 500...]

I'm trying to apply it to Warcraft 3, and so far I managed to get 90% of the effect I am looking for. The only problem is that it's not 100% accurate, I am pretty sure I am doing something horribly wrong.

JASS:
Set udg_RD_Offset4 = ((udg_RD_Offset2 x udg_RD_CurrentTime) x (udg_RD_CurrentTime - udg_RD_Timer2Config))

Set udg_TempReal = udg_RD_Offset2 + udg_RD_Offset4

Half way through I have to change the direction of the movement to down with an if/then/else statement, otherwise it just keeps going up.

RD_Offset2 is the initial velocity, which is set to 15.

Timer2Config is the total time of the timer, which is set to 2.

When the timer ends, the unit is still ever so slightly above the ground.

Edit: I can't seem to figure it out, for now I am just going to replace it with a different kind of effect. Thank you for your help.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
RD_Offset2 is the initial velocity, which is set to 15.
Assuming that initial velocity in units per second and total time in seconds.

integrate2(Acceleration, 2, 0) + 2 * 15 = 0 // displacement must be 0 after 2 seconds
integrate2(Acceleration, 2, 0) = -30

Lets assume it is a constant acceleration, like real gravity.

integrate2x(k, 2, 0) -> kx^2/2 using x[2, 0] = 2^2k/2 - 0k = 2k

2k = -30
k = -15
From the instance you launch, a constant upwards acceperation of -15 units per second will guarantee that that the height difference is 0 after 2 seconds.

Alternatively one can work out the height at any given time by integrating this constant acceleration twice and adding in the integration of the constant initial velocity.

y = -15x^2/2 + 15x
Here is the arc it produces... Not very meaningful in WC3 as it barely gets off the ground but it is what you want after all.
upload_2017-2-17_22-3-22.png

Might want to try a higher initial speed, eg 1000.
y = -500x^2 + 1000x
upload_2017-2-17_22-4-52.png

Which is basically the parabola I provided to you above.

y= -500 * x * (x - 2)
Or in other words...
y= -[height of peek] * x * (x - [time of landing])
 
Level 11
Joined
Aug 6, 2009
Messages
697
Well adding will always have floating point error, although that should not be significant in this case.

There is probably some sort of logical error so that you miss a tick or so of height change.

  • Custom script: set udg_RD_Offset4 = -500 * udg_RD_CurrentTime * (udg_RD_CurrentTime - udg_RD_Timer2Config)
  • Animation - Change TempUnit flying height to RD_Offset4 at 0.00
When I do this, it works fantastically.

The problem is that when I add the RD_Offset4 to the current flying height, it adds +1 to 500 every tick, because it's simulating the parabola height change. Every tick it adds RD_Offset4 to the flying height, when instead, the flying height should be changed to RD_Offset4.

Is there any way to fix this problem?
 
Level 11
Joined
Aug 6, 2009
Messages
697
Set the flying height to RD_Offset4 instead of adding to current flying height? If that does not work because you need other offsets then get current flying height, subtract RD_Offset4 from last tick, and add new RD_Offset4 for the current tick.

May I call you Master Doctor Super Lord Good?
It worked, thank you for bearing with me.
 
Level 11
Joined
Aug 6, 2009
Messages
697
Which of the two methods did you end up using?

  • Set RD_Offset5 = RD_Offset4
  • Custom script: set udg_RD_Offset4 = -(udg_RD_MaxHeight2) * udg_RD_CurrentTime * (udg_RD_CurrentTime - udg_RD_Timer2Config)
  • Set TempReal = (RD_Offset4 - RD_Offset5)
  • Animation - Change TempUnit flying height to ((Current flying height of TempUnit) + TempReal) at 0.00
I used this: y= -[height of peek] * x * (x - [time of landing])
The other one didn't work for me very well, or I kept messing it up. I forgot if it worked or not after trying to mess with it for hours.
 
Status
Not open for further replies.
Top