0
\$\begingroup\$

How can I use game-maker to detect the force in a collision between two mobile (not fixed) objects?

This is used for damage calculation and possibly compression calculation.

My problem is this: while net force can be calculated using mass and acceleration, the idea of damage is focused on the individual components of the force applied on an object. For instance, if a car is pushing another car against a wall, even though there are no acceleration, people will logically feel like some damage must be done to both cars because forces were conferred on them. I want to know if there is some underlying mechanism in game maker's physics system (I use the latest version) that actually calculate a reaction force from the wall on the car so I can use it to calculate damage.

\$\endgroup\$
  • \$\begingroup\$ What did you try? \$\endgroup\$ – Vaillancourt Mar 2 '16 at 14:02
  • \$\begingroup\$ I tried to calculate the acceleration by recording the velocity of the objects before and after a frame (using the step before and step after event) but the results are often inaccurate, and this does not account for situations where a mobile object is "crushed" against an immobile object, such as a car being pushed against a wall by another car. \$\endgroup\$ – user289661 Mar 2 '16 at 21:38
  • \$\begingroup\$ Are you using the new physics engine? The old one with bitmasks? Or are you setting up your own physics collision detection system...? More info would be appreciated, we can't help you if you don't help up figure out your problem. \$\endgroup\$ – liggiorgio Mar 3 '16 at 14:18
  • \$\begingroup\$ I worked with another physics engine (ODE), not in game maker, and from that experience, the forces given from the engine were only partially reliable for that kind of calculations. Perhaps you should right away add your own layer to calculate this kind of information, you'll be able to tweak it to your needs. \$\endgroup\$ – Vaillancourt Mar 4 '16 at 12:35
1
\$\begingroup\$

I found a solution to the particular problem that I am having:

I continue to use the physics system but instead of trying to dredge out the reaction forces acting on the object, I chose to create a "collision box" which I "attach" to all objects.

The box consists of multiple rectangles that surround a central geometry. The following code was used to give this rectangles, which I call "collision bars", a "springy" behavior:

if x!=X //X is the displacement of the collision bar from the central geometry
{
physics_apply_force(x,y,(x-X)^3,0)
}
//and the same is done for y

This means the collision bars are mobile around the central geometry but restores to a specific relative location.

If another object collide with the collision bar, there will be a displacement in the location of the collision bar, and the greater the "force of collision" the greater the force, and I can consequently use the collision bar's displacement from the central geometry to calculate the force applied on the object from a specific direction.

This may not be the most efficient or the most elegant method, but it works for the game that I am working on well enough.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.