Advertisement

simple collision response

Started by December 14, 2002 10:38 PM
6 comments, last by Abob 22 years, 2 months ago
I have been thinking about physics before I start coding a new game (2D). There are two objects. Each object has a Mass and a Velocity Vector. There is no gravity of friction. If the two objects run into each other. Each object puts its force (mass * Velocity) into the other object witch Turns that into acceleration with (acceleration = force/mass). Is that right? The problem with it is if two objects of equal force run into each other they wont bounce. They will just stop. Thanks for any help
Arrg!!
Force = mass * acceleration, not mass * velocity. mv is momentum (p), which is also conserved in collisions (well, it''s only completely conserved in 100% elastic collisions, which do not exist in the real world, but that''s fairly negligible for games'' sake).

And yes, if two objects with equal force hit each other, they will simply stop, provided that they hit head on, with the forces going in exact opposite directions. If it''s at an angle, then there will be some deflection.

Basically, for collisions, you really want to deal with momentum rather than forces (for the most part), so I suggest you look into that a bit (it''s really not too complicated). I''ll sum it up here:

m_1*v_1 + m_2*v_2 = m_1*v_1'' + m_2*v_2''

Where the '' (prime) signifies the velocity after the collision (the other v''s being pre-collision velocities).
Advertisement
quote:
Original post by CmndrM
mv is momentum (p), which is also conserved in collisions (well, it's only completely conserved in 100% elastic collisions, which do not exist in the real world, but that's fairly negligible for games' sake).


The momentum will be preserved in a system completely free from outer dependencies, but that does not necessarily constitute a completely elastic collision. A completely elastic collision is when the kinetic energy is preserved, not the momentum.

quote:
Original post by CmndrM
And yes, if two objects with equal force hit each other, they will simply stop, provided that they hit head on, with the forces going in exact opposite directions. If it's at an angle, then there will be some deflection.


First of all, I think you mean with equal speed, the velocities being antiparallel. And if you do, that will not necessarily turn into a dead stop for both objects. Yes completely elastic collisions does not exist in practice (except between atoms), but that doesn't mean the collision has to be completely plastic either. The objects will probably have a nonzero coefficient of restitution, making the objects' velocities being preserved at least to a certain extent.

/Gee .

[edited by - Gee on December 15, 2002 2:49:40 AM]
---GUI Programming Division Manager at Wildfire Gamesworking on the 0 A.D. project
Why dos force = mass * acceleration?

If object x crashes into a brick wall

How do I calculate how much force is put into the wall

Is it x’s mass * x’s acceleration?

Acceleration = rate of change in velocity right?

It seams to me that it should only mater how fast the object is going not how fast it is accelerating.


Also how dos bouncing work?

Say an object has a value for how will it bounces (0 to 1).

When that object puts force into another object would it add the inverse of that force * it’s bounce value to its self?

Thanks for any help
Arrg!!
You''re right, the collision response is static in the eye of the acceleration, it''s the velocity that matters.
And yes, if I''ve understood you correct you want a value from 0 to 1, to represent an object''s capacity to bounce. I mentioned this before, it''s the coefficient of restitution.

When the object hits the wall (let''s say a wall with infinite mass so it cannot be moved), a force parallel to the wall''s normal will be added to the object. Depending where on the object the collision occurs, a change in the angular velocity will take place, but for you I suggest starting off with static orientation for your dynamic objects (i.e. they can''t rotate). Anyway, as said, a force parallel to the wall''s normal is added to the object, but what''s the force''s magnitude?

Check this out, I wrote it couple of hours ago... It should give you a basic idea... Notice e in there too, watch the result if it''s set to 1 and 0 respectively.

To sum up what I wrote in the other thread:

v2 = v1 - ((1+e)v1 . n)*n
v2 - outcoming vel
v1 - initial vel
e - coefficient of restitution
n - wall''s normal
(Notice you don''t need mass because the wall is immobile, if we were modeling two dynamic objects'' collision, mass would be of importance)

Having any problems implemending, just let me know... cheers

/Gee .
---GUI Programming Division Manager at Wildfire Gamesworking on the 0 A.D. project
Ok… Thanks all. One more question. How do I handle the collision (it in 1 dimension) of two dynamic objects where each object has
Velocity
Mass
coefficient of restitution (bounce).


Thanks for any help.
Arrg!!
Advertisement
Alright... Objects one outgoing velocity will be:

vA2 = vA1 + j/mA * n

and object number two:

vB2 = vB1 - j/mB * n

n is still the wall''s normal, note it can either be a collision between one of object A''s walls and one of object B''s corners, or vice versa. In either case, n is the normal of the wall.

Anyway, j is a bit more complicated this time, here goes:

j = (-(1+e)(vA-vB) . n) / (n . n(1/mA + 1/mB))

(

I just specify everything too:
j - impulse magnitude
e - coefficient of restitution
n - wall normal
vA1 - initial velocity of object A
vB1 - initial velocity of object B
vA2 - resulting velocity of object A
vB2 - resulting velocity of object B
mA - mass of object A
mB - mass of object B

If you are looking for a simpler solution though, you have to tell me a little more about your layout, is it boxes colliding, is it spheres, do they rotate, etc...

/Gee .
---GUI Programming Division Manager at Wildfire Gamesworking on the 0 A.D. project
quote:
Original post by Gee
If you are looking for a simpler solution though, you have to tell me a little more about your layout, is it boxes colliding, is it spheres, do they rotate, etc...



All the physics objects will be axis-aligned rectangles. They will not rotate(we do not have to worry about non aligned collisions)

The game world will be 2D 800x600.


Arrg!!

This topic is closed to new replies.

Advertisement