Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411514 Posts in 69376 Topics- by 58431 Members - Latest Member: Bohdan_Zoshchenko

April 27, 2024, 01:32:33 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Momentum and Gravity
Pages: [1]
Print
Author Topic: Momentum and Gravity  (Read 1287 times)
Alfonso Crawford
Level 0
**


View Profile
« on: April 25, 2009, 07:53:51 PM »

In my fighting-game, movement is pretty simple: whatever previous velocity is completely replaced, instead of being rotated or whatnot. The trick that I wish to pull is that each character has a unique weight. Each change in velocity is affected by a downward pull, but I don't know how to properly implement that pull.

My first theory involves a tutorial on momentum that I had found. If two masses are divided and the quotient is modified by one velocity, when only one velocity is involved; do both velocities get divided by eachother and get applied to a single mass, when only the velocities differ? I have no clue as to what I'm to do.

 Lips Sealed Ugh. Research on a need-to-know basis is very rough.
Logged
bateleur
Level 10
*****



View Profile
« Reply #1 on: April 25, 2009, 11:50:24 PM »

For elastic (perfect) collisions you want two things:

1) Momentum on each axis should be conserved. That is, adding up the combined momentum along some axis of all bodies after the collision should give the same total as before the collision.

2) The kinetic energy of your entire system should remain constant.

What you find if you do the sums is that you're solving a quadratic equation which turns out to have two solutions. One of these solutions corresponds to the state before impact and the other to the state after impact, so in effect each collision has an outcome which can be uniquely determined.

However... if what you're trying to implement is gravity then none of the above is particularly relevant anyway. Gravity takes the form of a continuous downward force proportional to the mass of each object. Consequently in order to seem remotely realistic it must be applied once per game cycle, or in some other way that takes into account the passage of time, rather than being applied during collisions (which are instantaneous - it therefore does not affect them at all).

Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #2 on: April 26, 2009, 01:20:56 AM »

Though you can do as bateleur suggests, it's generally easier to work in terms of restitution, as it works for inelastic collisions.

So it's time for some unnecessary algebra (unnecessary as you could have just looked up the answer):
If m1 and m2 are the masses involved, v1 and v2 the velocities before and w1 and w2 after, then:
Conservation of momentum: m1 v1 + m2 v2 = m1 w1 + m2 w2
Restitution: w2 - w1 = e (v2 - v1)
So multiply restitution formula by m1, and add to get
m1 v1 + m2 v2 + m1 e (v2 - v1) = m1 w1 + m2 w2 + m1 w2 - m1 w1
                               = (m1 + m2) w2

Which gives us w2. w1 is near identical to calculate.

This is all along the axis of the collision - velocities in the other axis are unaffected, unless you are modelling friction too.

You use this formula once per collision. Gravity and other forces can be applied inpendently by chaning the velocities at the start of each frame.

Of course, why bother with all this stuff when there are perfectly good physics engines that do it for you? It sounds like you've got a lot to learn, otherwise.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic