- Joined
- Mar 31, 2015
- Messages
- 28
EDIT: I realized I wrote lot more text than decency allows, so, in short: Is there a knockback system that will slide an unit to exact point (i.e. slide exact distance)? Or, how to do math for in this one to achieve just that?
I need a knockback system (because I'm rather too lazy to make it from scratch, despite excellent tutorials available).
I found this one, but it takes parameters as vectors.
It clearly says "This system cannot be used to throw an object to a target location without doing the math yourself" which would be fine if I knew how do that; alas, I can't figure the math I need to get the unit to land on exact point (or be knocked-back to exact point)
So, help with the math - for known unit location and target location - calculate starting speed for use in this system - would be very much appreciated.
Or, alternatively, another system that does the math for me, or explains how, or knocks-back units at fixed speed.
By the way, I figured the following (please ignore the rest if I misunderstood something and failed miserably):
I think these are all parameters I need for charge-like ability (i.e. not jump).
Inside the timer function, speed is calculated as:
EDIT: Did more math, still didn't figure it out.
After a while, I realized that you can't know both the distance and the time in advance - but you could use one to calculate the other.
Let's say that we want to knock back the unit across the ground, to a point exactly s units away. What starting velocity should the unit have?
As I understand this script, unit starts moving at some speed (given via parameter), let's call that velocity v0, and then decelerates at constant rate, called FRICTION_ITER_MULTIPLIER. Let's call that rate a. Eventually it will slow down to MIN_FOR_KNOCKBACK, and then it will stop. Let's call that final speed vn.
The number of iterations, i.e. the time it will take for that to happen, is unknown. Let's call it n (= time_in_seconds/CLOCK_PERIOD).
In first iteration, unit will move exactly v0 * CLOCK_PERIOD.
In second, it will move an additional v0 * (1-a) * CLOCK_PERIOD units.
In n-th, it will move v0 * (1-a)^n * CLOCK_PERIOD units.
Therefore, total distance unit will slide equals v0 * CLOCK_PERIOD * (1 + (1-a) + (1-a)^2 + ... + (1-a)^n). Knowing the formula for sum of geometric series, and replacing 1-a with r, we arrive at:
s = v0 * CLOCK_PERIOD * (1 - r^(n+1)) / (1-r))
This is a linear equation with two (unknown) variables. To solve it, we need another equation. Let's examine velocity.
The speed starts at v0 and decelerates at the rate of a, until it becomes as low as vn (see above).
In first iteration, speed is v0 * CLOCK_PERIOD.
In second, it is v0 * (1-a) * CLOCK_PERIOD units.
In n-th, it will be vn = v0 * (1-a)^n) * CLOCK_PERIOD units.
Replacing (1-a) with r, we arrive at second equation:
vn = v0 * CLOCK_PERIOD * r^n
We now have two linear equations with two variables. Apply math.
s = v0 * CLOCK_PERIOD * (1 - r^(n+1)) / (1-r))
vn = v0 * CLOCK_PERIOD * r^n
From second one we have:
v0 = vn / (CLOCK_PERIOD * r^n)
And combining the two, we have:
s = (vn / (CLOCK_PERIOD*r^n)) * CLOCK_PERIOD * (1 - r^(n+1)) / (1-r))
Simplifying the fraction, we have
s = (vn / r^n) * (1 - r^(n+1)) / (1-r))
Moving all constants (and known variables) to the left, we have:
s/vn*(1-r) = (1 - r^(n+1)) / r^n)
s/vn*(1-r) = 1/r^n - r
s/vn*(1-r) + r = 1/r^n
1 / (s/vn*(1-r) + r) = r^n
And from here, we can calculate n as:
n = log(r, 1 / (s/vn*(1-r) + r))
And from here, we can calculate starting velocity, as we now have n:
vn = v0 * CLOCK_PERIOD * r^n
That was a LOT of math for something so "simple" as knocking the damn footman 600 units away. Either I missed something obvious or that much math is actually necessary (I used this for Log).
I made this in jass to test:
However, it doesn't really work as it calculates wrong. So due to either my misunderstanding of how KnockBack works, or my starting assumptions, or lack of math skills, I didn't solve this. Help?
I need a knockback system (because I'm rather too lazy to make it from scratch, despite excellent tutorials available).
I found this one, but it takes parameters as vectors.
It clearly says "This system cannot be used to throw an object to a target location without doing the math yourself" which would be fine if I knew how do that; alas, I can't figure the math I need to get the unit to land on exact point (or be knocked-back to exact point)
So, help with the math - for known unit location and target location - calculate starting speed for use in this system - would be very much appreciated.
Or, alternatively, another system that does the math for me, or explains how, or knocks-back units at fixed speed.
By the way, I figured the following (please ignore the rest if I misunderstood something and failed miserably):
JASS:
// A parameter for controlling the system clock, in seconds. 1/30 runs
// 30 times per second.
private static constant real CLOCK_PERIOD
// What fraction of velocity should be lost with every iteration of
// ground friction. Note that simulating an abstraction of friction in
// units per second overflows real precision numbers. Thus, you must
// adjust this according to your clock period.
private static constant real FRICTION_ITER_MULTIPLIER=CLOCK_PERIOD
// The minimum horizontal velocity a unit can be sliding before the
// system ignores it. A value of CLOCK_PERIOD*30 means the unit will
// stop sliding when its slide speed reduces past 30 units per second.
private static constant real MIN_FOR_KNOCKBACK=
I think these are all parameters I need for charge-like ability (i.e. not jump).
Inside the timer function, speed is calculated as:
JASS:
set tempDat.delX=tempDat.delX*(1.-FRICTION_ITER_MULTIPLIER)
set tempDat.delY=tempDat.delY*(1.-FRICTION_ITER_MULTIPLIER)
EDIT: Did more math, still didn't figure it out.
After a while, I realized that you can't know both the distance and the time in advance - but you could use one to calculate the other.
Let's say that we want to knock back the unit across the ground, to a point exactly s units away. What starting velocity should the unit have?
As I understand this script, unit starts moving at some speed (given via parameter), let's call that velocity v0, and then decelerates at constant rate, called FRICTION_ITER_MULTIPLIER. Let's call that rate a. Eventually it will slow down to MIN_FOR_KNOCKBACK, and then it will stop. Let's call that final speed vn.
The number of iterations, i.e. the time it will take for that to happen, is unknown. Let's call it n (= time_in_seconds/CLOCK_PERIOD).
In first iteration, unit will move exactly v0 * CLOCK_PERIOD.
In second, it will move an additional v0 * (1-a) * CLOCK_PERIOD units.
In n-th, it will move v0 * (1-a)^n * CLOCK_PERIOD units.
Therefore, total distance unit will slide equals v0 * CLOCK_PERIOD * (1 + (1-a) + (1-a)^2 + ... + (1-a)^n). Knowing the formula for sum of geometric series, and replacing 1-a with r, we arrive at:
s = v0 * CLOCK_PERIOD * (1 - r^(n+1)) / (1-r))
This is a linear equation with two (unknown) variables. To solve it, we need another equation. Let's examine velocity.
The speed starts at v0 and decelerates at the rate of a, until it becomes as low as vn (see above).
In first iteration, speed is v0 * CLOCK_PERIOD.
In second, it is v0 * (1-a) * CLOCK_PERIOD units.
In n-th, it will be vn = v0 * (1-a)^n) * CLOCK_PERIOD units.
Replacing (1-a) with r, we arrive at second equation:
vn = v0 * CLOCK_PERIOD * r^n
We now have two linear equations with two variables. Apply math.
s = v0 * CLOCK_PERIOD * (1 - r^(n+1)) / (1-r))
vn = v0 * CLOCK_PERIOD * r^n
From second one we have:
v0 = vn / (CLOCK_PERIOD * r^n)
And combining the two, we have:
s = (vn / (CLOCK_PERIOD*r^n)) * CLOCK_PERIOD * (1 - r^(n+1)) / (1-r))
Simplifying the fraction, we have
s = (vn / r^n) * (1 - r^(n+1)) / (1-r))
Moving all constants (and known variables) to the left, we have:
s/vn*(1-r) = (1 - r^(n+1)) / r^n)
s/vn*(1-r) = 1/r^n - r
s/vn*(1-r) + r = 1/r^n
1 / (s/vn*(1-r) + r) = r^n
And from here, we can calculate n as:
n = log(r, 1 / (s/vn*(1-r) + r))
And from here, we can calculate starting velocity, as we now have n:
vn = v0 * CLOCK_PERIOD * r^n
That was a LOT of math for something so "simple" as knocking the damn footman 600 units away. Either I missed something obvious or that much math is actually necessary (I used this for Log).
I made this in jass to test:
JASS:
static method getRushSpeed takes real distance returns real
local real s = distance
local real a = FRICTION_ITER_MULTIPLIER
local real v0
local real vn = MIN_FOR_KNOCKBACK/CLOCK_PERIOD
local real r = (1-a)
local real n = Log(r, 1/(s*a/vn + r))
set v0 = vn / Pow(r, n)
return v0
endmethod
However, it doesn't really work as it calculates wrong. So due to either my misunderstanding of how KnockBack works, or my starting assumptions, or lack of math skills, I didn't solve this. Help?
Last edited: