# Jumping Physics - Fighting Game

This topic is 5401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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]

f=ma

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by Jacob RomanThe 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.

##### Share on other sites
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?

##### Share on other sites
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.

##### Share on other sites
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]

##### Share on other sites
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?

##### Share on other sites
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).

##### Share on other sites
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?

• 21
• 13
• 9
• 17
• 13
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!