|
-
bibuti.
 Originally Posted by joshstrike
Assuming you have a constant gravity acting on the character's y-velocity, and assuming the x-velocity is going to be constant throughout the jump, you should be able to take the horizontal distance divided by two and figure out how long in ticks the character will take to complete the second half of the arc in x-distance. If you know that, just create a scratch acceleration var and run it that many times in a loop, adding the value of itself+gravity each time, and the y-position of the end point minus that total gravity should give you the top of a parabola that's halfway between start and finish and at the right height above the endpoint to make the jump look realistic.
Thanks for your reply!
Your explanation almost makes sense to me, but I'm lost when you mention "a scratch acceleration and it run it many times in a loop". The thought of calculating a parabola of motion seems to be the most elegant solution though.
Could you elaborate a bit on this method? Again, thank you for your help.
i'm obsessed with video games.
-
Senior Member
Basically at the top of the parabola, your upward velocity is wiped out by gravity, and the character should have a y-velocity of zero.
So the next tick, the character will fall 1 pixel, let's say, if gravity = 1. It will have a downward y velocity of 1. In the tick after that, it will have a downward velocity of 2, and will have traveled a total of 3 pixels. In the tick after that, it will have a downward velocity of 3 and will have traveled 6 pixels.
The idea of a scratch var is just a quick way to make that calculation to determine the distance it will fall off the top of its arc, given that you know how long it needs to fall to cover the 2nd half of the x-distance.
Code:
var testvel:Number = 0;
var ydist:Number = 0;
var ticks:Number = (xdistance / 2) / xvelocity;
for (var k:int=0;k<ticks;k++) {
testvel += gravity;
ydist += testvel;
}
At the end of that, ydist should equal the distance that the character will fall vertically from the top of a parabola, dependent on the strength of the gravity and the length of time it's falling. There are other, trig ways of calculating this but I'm not hip to them, being as I'm something of a dropout. But since you can get the length of time the character needs to fall based on half the x-distance between start and finish, the ydist represents the additional height over the finishing position that the character would be at when it reaches the top of its arc.
Hope that makes some kind of sense...
-
bibuti.
Hey I just wanted to thank you joshstrike for your help.
I've found my solution, which came about because of your suggestions regarding the calculation of a parabola.
So yeah, thanks!
i'm obsessed with video games.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|