| 05-01-2008, 10:22 AM | #1 |
Hey, for a spell that I'm making the last days I got struck to find a correct formula for moving. What I want is this: I have a unit with a speed of 15 units / 0.04 seconds (when this certain movement starts). The unit must reach a distance of 100 units in 0.4 seconds. That means that I got 10 intervals in which I have to multiply my speed with a certain acceleration to lower it in an constant way, so that my dummy will have reached the location in 0.4 seconds! I tried using the standard physic movement formulas but failed, probably because I don't really know where to put the 10 intervals in which I multiply the speed with a one factor. 10 Intervals because the targeted location should be reached in 0.4 seconds with a period timer of 0,04 seconds. Through testing I got to a factor of 0.96 which is very close to the "perfect" value. I almost get a distance of 100 units with it. But I want a formula because I like to have as many parameters of the spell to be customizable, just as as the speed factor. Thus I need a general formula. I would be very, very thankful if someone could help me here. I tried physical movement formulas like 1 1/2 hours without getting a correct result ![]() |
| 05-01-2008, 11:12 AM | #2 |
First: You should be subtracting a constant value from the knockback speed each update in order to properly simulate friction. Don't multiply. Second: You're picking too many constraints for your knockback. The distance it covers and the time required to stop should be a natural result of the initial speed and the de-acceleration. Those are the only values you or your user need to customize. |
| 05-01-2008, 11:23 AM | #3 |
This is no knockback. It's a spell with a location. And to reach that one I have to use fixed values. And I don't make something easy like the same speed or the same acceleration during the whole movement. |
| 05-01-2008, 12:16 PM | #4 |
I guess you look for this formula acceleration=(10/15)^(1/10) |
| 05-01-2008, 02:55 PM | #5 |
Ahh looks like 0.96 was not almost perfect. Sorry. And well with your formula I get 0,96. I also don't know why there isn't the max. distance parameter (in my case 100) involved. |
| 05-01-2008, 05:19 PM | #6 |
Well I used an exponential function: y = b*a^x. Alright I admit I should have explained myself better... y is the distance you want to achieve (100 units / 0.4 seconds), b is the current speed (15 units / 0.04 seconds), a the unknown acceleration and x the intervals (10) Now this formula is used: a = (y2/y1)^(1/(x2-x1)) If we set your x (10) as the x2 then x1 is 0 because we start at 0 intervals, and your y (100 units / 0.4seconds) as the y2 then y1 is b (15 units / 0.04 seconds) because y1 is the b value at 0 intervals (x1). Now just inserting a = ((100/0.4)/(15/0.04))^(1/(10-0)). In my earlier formula in the (y2/y1) part I said 100/0.4 = 10/0.04 and then removed the two 0.04 divisions so I got 10/15... |
| 05-01-2008, 06:04 PM | #7 |
Hmm but when I do this: 15 * 0.96 + 15 * 0.96^2 + 15 * 0.96^3 .... + 15*0.96^10 the result is : 120.832 |
| 05-01-2008, 09:25 PM | #8 | |
Quote:
If the thing is supposed to be slowing down due to friction with the ground, you're doing it wrong. |
| 05-02-2008, 06:41 AM | #9 |
Try looking at my jump map, the code would be very similar. Found at http://www.wc3campaigns.net/showthread.php?t=81446. |
