Game Development Community

Vehicle collision using impulse system

by Very Interactive Person · in Torque Game Engine · 08/29/2004 (2:23 pm) · 11 replies

I want to script an impulse system for vehicle collisions. In the onCollision everything I need is actually available, forward vector of the objects, objects mass, speed, ... But i'm missing some math knowledge to write code that will give the collided object an impulse depending on the direction, speed and mass of the initial object.

For some time now I'm using more or less the code from this thread in my projects: http://www.garagegames.com/mg/forums/result.thread.php?qt=3906
This code however gives a more upward impulse and is totally unrealistic. For arcade games this can work, and its more or less what I used in the game I did 2 months ago, but now I'd like to use something better, not totally realistic, but better then what i'm using now.

I'm sure its possible becuase my explosions give the objects in the explosion radius a realistic impulse (objects get thrown in the right direction, depending on where the explosion is in relation to the object).

Any ideas? Anyone who has scripted this before and willing to discuss or even share his code?

#1
08/31/2004 (10:27 am)
Anyone??
#2
08/31/2004 (10:31 am)
Have you tried the info from this resource?
#3
09/02/2004 (4:11 pm)
Doesn't help me at all... That's some code for impulses and explosions... I have something like that. Like I said, I have impulses, but I'm looking for code that gives a correct impulse depending on speed/mass/direction/position/...
#4
09/04/2004 (1:37 pm)
Have you tried directly manipulating the Rigid?
#5
09/04/2004 (9:54 pm)
How about something like this:

vector = vectornormalize(vectorsub( obj1, obj2)) (or the other way around)
this should give you the vector between the two objects and then multiply that times
mass * speed * (optional const) / dist

do an applyimpluse with this val and it should be good, no?


-s
#6
09/05/2004 (1:45 am)
Ah, this is more what I'm looking for. 2 questions tough, what is "dist"? and where would I apply this impulse, I mean on what position?
Anyway i'll try this and see if more realitsic then what i'm using now.
#7
09/06/2004 (3:59 pm)
Dist would be VectorDist( obj1, obj2) (the distance from the explosion, although it should probably have a logarithimic for realism). Do an applyimpulse on the object, applyimpulse is a method call on an object, (the center I'm sure), not on a position.

good luck!!


-s
#8
09/08/2004 (11:15 am)
%col.applyImpulse(position, impulsevec);

That's how I tought it worked.

So, I'm using %col.applyImpulse(%col.getWorldBoxCenter(), %impulseVec), and that seems to work fine.

Anyway, your comments where helpfull, the impulses are a lot more realistic now... only some bugs to iron out, like when you drive into someone's back (moving object), instead of giving the object a forward impulse and me a backward impulse, everything just kind of freezes and starts lagging until I stop driving forward... It helps when I make the wheels inside the collision box, so I think that has something to do with it.
#9
09/08/2004 (8:47 pm)
Really, applyimpulse uses a position as its first param.? Guess its been a while!!!

You are probably running into torque's physics intermingling w/ what you are implementing, or maybe the impluse is not "long" enough, as the real physics would take place over time.

Good Luck!


-s
#10
09/14/2004 (6:48 pm)
I believe energy applied will be the inverse the square of the distance multiplied by the intial energy from the blast. Think of the energy coming from a sphere is space. It will spread out equally in all directions. The total energy will spread out over the entire surface of the sphere representing the blast radius. If the explosion is on the ground more energy will be reflected off the ground and upward thereby increasing the upward blast.

If you want more realism then apply the energy over time as the concussion wave will take time to spread out. Although, it may happen so quick that you would not notice the difference anyway. But, it would be cool to have a person get hit by a huge explosion if they are a mile away some time after the initial blast. One intersting thing to note. Someone in my town had a natural gas explosion in there house and the blast cracked the walls of a nearby house. My house felt the explosion even though I was miles away. It felt like someone hit the house with a hard object. It did not do any damage, but the concussion could be felt miles away. We did not hear the explosion at all.
#11
09/19/2005 (8:18 am)
Did anyone get any further with this method? I think it might be useful to me.