| 01-02-2009, 07:00 AM | #1 |
I'm trying to put together a parabolic jump that does exactly what I want it to do. Unfortunately, I don't think I payed enough attention in math. Here's what the jump needs to do:
So, basically I need to calculate a, b and c in y=ax^2+bx+c, and then throw in x (distance) to get y (height) at every time step. y would be in absolute height, and I'd subtract out the Z of whatever the current location is, and set my unit's fly height to that. I suppose the equation could be in other forms too, like y=a(x-h)^2+k Example:struct Jump unit u real a real b real c real old real dist real speed real xspeed real yspeed method run takes nothing returns nothing local real x=GetUnitX(.u)+.xspeed local real y=GetUnitY(.u)+.yspeed local location l=Location(x,y) local real z=GetLocationZ(l) local real old=.old set .dist=.dist+.speed set .old=a*.dist*.dist+.b*.dist+.c //it's actually new, but it'll be old by the next timestep call SetUnitX(.u,x) call SetUnitY(.u,y) call SetUnitFlyHeight(.u,GetUnitFlyHeight(.u)+.old-old-z,0) //we do this for dynamicism; if he's jumping and then gets hit by an uppercut spell, //we don't want the two conflicting. So, we simply calculate the change in height that he would have experienced anyway, and apply that change. call RemoveLocation(l) set l=null endmethod endstruct So how do I calculate a, b and c when the spell is cast? Or, do you have another way to do what I'm proposing? Random Thought: I seem to remember something where a=gravity, b=initial speed and c=initial height, so would that imply that a is a constant, c is self explanatory, and I just need to solve for b? How would I do that? |
| 01-02-2009, 07:11 AM | #2 |
This might help: http://wc3campaigns.net/showthread.php?t=102077 |
| 01-02-2009, 07:17 AM | #3 |
This does exactly what you want. |
| 01-02-2009, 07:23 AM | #4 |
The parabola function is not helpful, nope. Alright, I'll take a look at that system. Was bugging a little when I tested it, so I'll just rip the code out and vJass it... |
| 01-02-2009, 08:19 AM | #5 |
I have a system as well. It's fairly old, but the math itself is simple. |
| 01-02-2009, 12:47 PM | #6 |
I think projectile motion can use the equation 9.8x^2 + bx + c (only remembered a) can be used for "rocket" problems in math and such. Anyway, I would try doing this: Take the difference in Z heights of the target and start locations and "factor it in" somehow, like addition to the total Z-offset of the parabola. That way, if you are going uphill you will increase the Z-offset of your arc, and if you are going downhill the negative height will compensate. I'm no math expert, just an idea. My guess is Dusk's system is the right choice, though I haven't looked at it. |
| 01-02-2009, 01:29 PM | #7 |
a is equal to gravitational acceleration, something like -1000 b is the starting velocity, this is the value you need to calculate c is the starting z offset. With a constant horizontal velocity v, the horizontal distance between the caster and the target d and the vertical distance z, b is calculated as b= -a*(d/v)/2 + z/(d/v) |
