How do I find out the violence of an impact (physics)

0 favourites
  • 13 posts
From the Asset Store
Use this game pack to create your own game, modify the existing game or simply take a look and see how it was made.
  • So i have two side-viewed physic cars (or a car and a wall, for that matter) which eventually collide. Depending on the violence of the impact, cars may get dented, seriously damaged or just explode into pieces. How could this be expressed as code? Googlin around I've seen that in order to determine the impact force I'd need an "acceleration" parameter (apart from things as mass and velocity) that i can't find. And even if I could i'm not sure i'd know what to do with it either... How is this usually done then?

    Thanks!

  • Maybe what you want is the kinetic energy or maybe the impulse of the collision. Now that I think about it it can be thought of as the acceleration. Basically the change of speed. You can calculate the X acceleration like this. Y can be done similarly, and the total can be calculated with both: distance(0,0,ax,ay).

    Var lastVx=0

    Var acceleration=0

    every tick

    --- set acceleration to (car.physics.velocityX-lastVx)/dt

    --- set lastVx to car.physics.velocityX

  • Wouldn't it just be based on speed at the time of impact?

    Other factors might be angle of impact and acceleration but I think speed is the main factor.

    That would be measured as velocity in physics.

  • It's the change in velocity. In simple cases like hitting the wall at 60mph the car would go from 60 to 0 so the speed would be the change in speed. Still you'll need to store the velocity before colliding because after the hit the the velocity will be 0 (if it doesn't bounce).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Unless you are doing that for a science project where you need exact measurements for damage I would just put a blank sprite in front of the wall and measure velocity when it collides with the sprite and adjust your damage according to that.

  • R0J0hound

    lamar

    Hey, thanks for your answers guys. Im a noob at physics and will need some time to dig all this

    I'm not really aiming for any kind of realism either, so i'd be inclined to take the simplest easiest path available. Unfortunately it may be a bit more complex still: what about two cars (yeah forget about the wall) moving in the same direction but at different speeds that eventually collide...? Shite I'm not even sure if i'm asking the proper questions. Hold on.

    This is what I'm working on. I'd like the cars to receive damaged whenever they hit each other (or them kegs) with certain violence -- not like blowing into pieces each time they get a bit scraped. Cars would also break by sections (not many: snout and butt around a base frame), so it's important to determine which areas are affected by the impact: thus, if you crash against the car in front of you, your snout section and the other car's butt section would be affected.

    The plan was, create an invisible sprite wherever the collision takes place and assign it a variable with the strength of the impact, and check which sections are overlapping. If that approach is fine, I guess the question would be: which value should i assign to said variable.

    Some thing easy! If i understood R0J0 properly (which I may or may not), the proper thing would be to calculate an impact force for each car? No wait twas acceleration rate for each car... Well if i can summarize it all in one value that makes sense that would be great. Maybe some difference between velocities or something...?

    Thanks again for your patience

  • R0J0hound

    lamar

    Hey, thanks for your answers guys. Im a noob at physics and will need some time to dig all this

    I'm not really aiming for any kind of realism either, so i'd be inclined to take the simplest easiest path available. Unfortunately it may be a bit more complex still: what about two cars (yeah forget about the wall) moving in the same direction but at different speeds that eventually collide...? Shite I'm not even sure if i'm asking the proper questions. Hold on.

    This is what I'm working on. I'd like the cars to receive damaged whenever they hit each other (or them kegs) with certain violence -- not like blowing into pieces each time they get a bit scraped. Cars would also break by sections (not many: snout and butt around a base frame), so it's important to determine which areas are affected by the impact: thus, if you crash against the car in front of you, your snout section and the other car's butt section would be affected.

    The plan was, create an invisible sprite wherever the collision takes place and assign it a variable with the strength of the impact, and check which sections are overlapping. If that approach is fine, I guess the question would be: which value should i assign to said variable.

    Some thing easy! If i understood R0J0 properly (which I may or may not), the proper thing would be to calculate an impact force for each car? No wait twas acceleration rate for each car... Well if i can summarize it all in one value that makes sense that would be great. Maybe some difference between velocities or something...?

    Thanks again for your patience

    You change the whole scenario with two moving objects. Then at point of impact you need both objects velocity and Rojo suggestion would work best.

    For a wall or non moving object the sprite trigger to get velocity would work.

    Just thinking out loud and you could pin a blank sprite to the front and rear bumpers and use that as a trigger to measure velocity at time of impact. Not exact but close enough I doubt anyone would notice.

  • For completely accurate physics: for each car, compute velocity change, then square it. This will give you the amount of energy absorbed (total damage done) in the collision on each car. Just follow the suggestions from R0J0hound above.

    It is an artistic judgement call to determine what that damage looks like, and In the end, this is a lot more important than the math.

  • lamar

    cjbruce

    Thanks a lot, people, you helped me greatly. Well i hope you did -- i'll let you know XD

    I worry a bit that i'm gonna be storing a lot of variables every tick (plus everytick minus one, arguably) which might hit performance -- as every damn thing does. Well hopefully some is-onscreen condition will fix me there.

  • A lot of things are done every tick and saving an expression to a variable is negligible in my opinion.

  • A lot of things are done every tick and saving an expression to a variable is negligible in my opinion.

    And trust, your opinion concerning physics and C2 is more than enough for me I tend to overworry with performance (just at the end it often seems that i hadn't overworried that much after all).

    Nevertheless,

    It is an artistic judgement call to determine what that damage looks like, and In the end, this is a lot more important than the math.

    And that's so very true too. In the game's current state, collisions are destructive or not on a purely random basis... and it looks pretty good, curiously -- it's all fast and dirty and plain dumb luck does not look too weird or outta place. As i'm trying to introduce some maths (and so calculate real forces), well... let's say it needs a lot of tweaking still. If the force is a square it gets a bit too, hum, nonlinear -- results are so volatile. I'm experimenting now with other values, even if that's not so realistic. But i'd lie if i said the lazy random solution aint tantalizing...

  • ,

    Food for thought, if you want to really go nuts with the math:

    1. The damage can be expressed as proportional to the loss in kinetic energy, which is proportional to the square of the change in velocity.

    2. In real life, this damage would be distributed over a volume. How this volume of damage appears from a 2D side view could be completely unpredictable depending on the internal structure of the car and where the car was hit.

    In the end, the random approach might be the best-looking model of all. I would totally go with it if it looks good.

  • When I want to cause damage I usually throw in some fire and explosions effects. Hell that looks good in any game lol!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)