Jumping Physics - Fighting Game

Started by
37 comments, last by VThornheart 19 years, 6 months ago
I'm creating a fighting game that's gonna be Mortal Kombat vs Street Fighter, with graphics I ripped of from various arcade fighting games using Nebula & MAME. Anyways, I want the jumping physics to be based on a characters weight,gravity that's based on Earth gravity (9.8 is earth gravity) as well as the force that has been done to launch a person from the ground. That way there, the heavy people in the game don't jump as high, like in the REAL world, unless they have the force to do so. I need the maths for actions such as jumping straight up, and jumping forward/backward. And if you can, not only provide a formula, but a code example as well. I went to sites like www.physicsclassroom.com where they provided a 100 different formulas, but I got confused on what formula to use and how I was gonna use them, which is why a code example would be better. I tried everything I could but failed. Please help me. Thanks. [Edited by - Jacob Roman on September 22, 2004 5:01:30 AM]
Advertisement
f=ma
The formula is missing gravity. And a code example would help too. ;) Also I don't think that'll work cause if you have a person that's gonna jump straight up (Y), if you keep multiplying twice to that value, you end up going up, Up, UP, etc...unless somewhere in there is gonna be a negative number. The fighter has to go up, and eventually he'll slow down going up, and come back down. Sine and Cosine would help do this, but I'm having a hard time working with it.
Quote:Original post by Jacob Roman
The formula is missing gravity. And a code example would help too. ;) Also I don't think that'll work cause if you have a person that's gonna jump straight up (Y), if you keep multiplying twice to that value, you end up going up, Up, UP, etc...unless somewhere in there is gonna be a negative number. The fighter has to go up, and eventually he'll slow down going up, and come back down. Sine and Cosine would help do this, but I'm having a hard time working with it.


not quite...

f = m*a is certainly very important here in its different forms. (f being gravity here)

f*dt = m*dv is also important.

basicly it goes like this:
when a character initiates a jump, he exerts a certain force on the ground for e certain amount of time, giving him an impulse f*t. as can be seen from the above formula, you can divide this by his weight to obtain the speed with which your character takes off.

at this point your charater is flying upwards. now apply f=m*a and f=m*-g (thus simply a=-g) to get the acceleration, and use dv = a*dt to obtain the change in speed. then update the position accoring to speed. if you do this correctly, the character will follow a parabolic path, first going up then going down.
Thanks Eelco for a better description of the formula. When I get home from work & college, I give it a whirl in a test program. If I have problems, I'll let ya know ;). Oh by the way, I know (f = force), (m = mass), (a = acceleration) and (g = gravity), (but dv and dt?) Isn't that velocity and time? If it is, how can I use it for the sprites X and Y coordinates?
Since you just want to look at the effect of gravity, you could just integrate the equation and use the following:

y - y0 = v0*t -1/2*g*t^2

where y0 and v0 are the initial position and speed at time t=0, and y is the position of your character at time t.
g is the acceleration due to gravity (~9.8 m/s^2).

Hope this helps.


Michael Brennan, Ph.D.
d/dt = derivative

The equation can be re-written as f = m * (dv/dt), which means that force is equal to mass times the derivative of the velocity with respect to time. The derivative of position is velocity, and the derivative of velocity is acceleration, hence:

f = ma = m * (dv/dt).

As for the rest, sorry, I can't help.

Edit: Fixed some of the terminology.

[Edited by - Del Snd of Thndr on September 22, 2004 5:31:43 PM]
~del
Still having a little trouble after using all those formulas. Can someone please show me a code example. Either in Visual Basic or C++, so I can understand how to implement it?
I think that dv is the velcity delta, or the change in velocity, and dt is te time delta, or the change in time (I think that it is chage from the last time you used the formula).
____________________________________________________________Programmers Resource Central
This is what I have:

Private Declare Sub Sleep Lib "kernel32" (ByVal Milliseconds As Long)

Dim Y As Single

Private Sub Form_Activate()

DrawWidth = 10

Y = 450

Dim F As Single, M As Single, V As Single, T As Single

M = 10 / 2.2 'lbs to mass (kg)

V = -9.8

T = 0

Do

DoEvents

Cls

T = T + 1

F = M * (V / T)

'Print f

Y = Y + F

'Print Y

PSet (100, Y)

Sleep 16

If Y <= 0 Then Y = 0

If Y >= 450 Then

Y = 450

End If

Loop

End Sub



And the result is that it went up and slowed down, but continued to go up as it slowed down, and never came down. And the mass was messed up to. If it were heavier, it went up further as if it were lighter. Same goes with the gravity. Any other suggestions?

This topic is closed to new replies.

Advertisement