Collisions (ohysics) for Missiles, Bullets, Explosions etc


I struggle how to create collisions for bullets, missiles and all moving objects from shooting weapons.

I take into consideration Bullet (engine) for that, but I am not sure if isn’t take too much performance.
I thinking about, do it with raycast, but I don’t know how to raycast for objects like spheres or objects with custom shapes, because raycast is only 1dimensional line (ray from start point in to end point) and I need something like area damage for explosions. Imagine, when grenade explode near 4enemies, it affect all 4 enemies within explosion range.

What is best solution for that?




You may also look into PhysicsWorld::SphereCast(result, ray, radius, maxDistance), PhysicsWorld::GetRigidBodies(result, sphere) or similar functions.
In some cases you may want to use triggers instead. These rigid bodies - that had SetTrigger(true) called - will signal physics events without any forces being applied as a result.



One thing, what if bullet is going too fast? I turn ContinousPhysic Detection (I can’t remember the right name) and fast moving camera isn’t going throught objects anymore.
But from documentation, is mentioned it can slow down performance. Imagine I want have machine gun which shoot lot of bullets in high speed. Is it ok to make bullets with Bullets physic engine? Or raycast is better solution?
Maybe for player character it is not cost performance, but imagine if they will be enemies with machine guns too.


Ironically you’re probably better off by indeed casting a ray (or several consecutive ones).


My idea is create object (simple bullet maybe billboard with bullet texture) and it will be casting ray for object detection as he travel in scene. It is good idea? Only problem is, if he will moving fast, but I have some ideas how to make it correct. Or it is better only cast ray and make damge for first ray hit? But this is unrealistic when objects will be in different distance.


You can use raycast with a bullet velocity as the ray length. Perform raycast between bulletPos and bulletPos + bulletVelocity if no hits were registered you’re safe to move your bulletPos to bulletPos + velocity.
keep repeating this process until you hit something or your bullet reach max distance (goes out of level bounds).


You’d actually want to ray cast with bullet velocity * time since last frame or it will overshoot. If they’re slow bullets you could also segment it to trace an approximately parabolic arc from gravity (but of course that would be somewhat more expensive).


Just so you know: In my game, bullets are affected by gravity and there’s penetration logic. Instead of using a rigid body, I just cast rays all the time. Much less buggy.


Thanks all for posts. Solution like use bullet velocity and time for the ray distance was what come to my mind when I started thinking about it. But thanks to confirm the idea.

I did bullets with raycast system, which do damage to object. I am going try something with area damage.

smellymumbler thanks for share experience.