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

Get help using Construct 2

Post » Fri Mar 03, 2017 6:45 pm

Image

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!
B
23
S
11
G
6
Posts: 181
Reputation: 5,003

Post » Fri Mar 03, 2017 8:06 pm

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
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Post » Fri Mar 03, 2017 10:32 pm

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.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » Fri Mar 03, 2017 10:45 pm

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).
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Post » Fri Mar 03, 2017 11:35 pm

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.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » Sat Mar 04, 2017 12:40 am

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

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 :)
B
23
S
11
G
6
Posts: 181
Reputation: 5,003

Post » Sat Mar 04, 2017 12:50 am

megalocrator wrote:@R0J0hound
@lamar
Hey, thanks for your answers guys. Im a noob at physics and will need some time to dig all this :geek:

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.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » Sat Mar 04, 2017 10:19 am

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.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
48
S
14
G
24
Posts: 405
Reputation: 16,658

Post » Sat Mar 04, 2017 9:16 pm

@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.
B
23
S
11
G
6
Posts: 181
Reputation: 5,003

Post » Mon Mar 06, 2017 7:43 pm

A lot of things are done every tick and saving an expression to a variable is negligible in my opinion.
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Next

Return to How do I....?

Who is online

Users browsing this forum: Blendi1223 and 45 guests