For moving body energy based damage, I use the distance.to of the two objects linear_velocity, but keep track of it each physics frame so I can catch the linear velocity on the frame just before the collision since the linear velocity reported on body_entered() reports the value after the collision. I think that makes sense, but am I doing it right or is there a more logical way than polling every physics frame to get that value? I feel like just because the results are useable, I’m confusing the distance.to with another type of vector function and my brain derp’d the trig.
Your math will depend on the damage model you want to create. Do you want a model that:
Damages both objects based on the estimated collision forces?
Favors the instigator of the collision?
…or a third way?
I have an answer for you but the answer will depend on what you’re looking to achieve. Using the velocity difference to compute collision severity is definitely valid. Damage resulting from such an approach will always be identical for all collisions between a pair of objects (given that you take into account the applied collision force, which you have).
Ah, that made me think about it a bit more. It’s a type of space shooter, top down, a bit like twinstick, ship pivots around center of screen as you fly about building up a space station, and ATM I’m using asteroids, which don’t get damaged like the hull of ships, you chip away at them, cutting them, to get them sized for easier tractor beaming and refining depending on refinery capacity. So Instigator doesn’t take the same hull damage as the player ship in that case ATM, but perhaps if enough, it would simply take a chunk out of the asteroid (which is a Polygon2D getting cut by another, if that makes a difference). That would need a threshold to compute size of cut or even if enough is reached to do the cut.
Not quite that far yet, but I would like to have collisions on baddies/other players as tractor beams can be weaponized. Also bulkhead, kind of Elite Dangerous like, is planned to be attached to ships so ramming is certainly something I should consider as well. So I guess it would be a bit of all of the above.
I’m happy that you’re excited about your idea, but I don’t need to know the theme of your game. I’m trying to help you solve a physics problem here.
From what I can extract from your description of your game, you have:
A player who receives a variable amount of damage from collision
An asteroid that fragments itself if the incoming damage is above a certain threshold
Player-to-player interactions that damage both players?
However, I’m still not certain of what you’re trying to achieve. Yes, I know what game you want to make but that hardly constitutes a technical description of how the systems within your game should behave.
Please describe what should happen when:
A player collides with an asteroid
An asteroid collides with a player
An asteroid collides with an asteroid
A player collides with a player
…and so on
How does your desired system act under the circumstances listed above?
I can’t help you implement a system if I don’t know its desired outcome.