Making a game with a lot of projectiles, possibly hundreds to low thousands on screen at a time. What would be the cheapest way to do this? Rigidbody3D or just a Node3d + mesh and fire a ray from it every frame to make sure it doesn’t pass through objects? Or if there is another method I am not aware of?
If you use RigidBody3d for thousands of projectile, then it would cost too much performance. You can try to use area3d for projectile, so whenever any enemy enter the area as body (collides with bullet), it will take damage.
raycast is the cheapest method of physics detection, a raycast that moves every physics frame and checks a distance ahead is the best way of simulating moving projectiles, and maybe even bullet drop.
the cheapest cheapest method is to just use the raycast from the character, this is called hitscan and is what has been used by FPS since doom.
at the time of half-life 2 games started incorporating physical projectiles for bullets, this allows projectiles to move at a constant speed instead of being instant, and allows adding bullet drop.
but, since forever (doom 1), missiles/rockets have been physical objects. if you know the trajectory (like it’s a straight line or a curve) you can use an Area3D, but if the projectile needs to curve or even bounce around like a plasma ball or a grenade that explodes after a timer, this has to be a rigidbody. but these are supposed to be objects that have a lower fire rate and so there are fewer of them at a given time. this in turn allows for explosions and AOE.
it also depends on the game you are making. a strategy game like warcraft 3 or a target based RPG like wow or lineage 2 did not use projectiles, you establish who the selected enemy is, and then a particle system appears between the player and the enemy, and then you can spawn an arrow on a random part of the enemy. this also applies to games like starcraft 2, where the marine’s fire is a particle system and the enemy slowly looses health.
but. another thing to consider is that we are in the future and any random phone could run a 10 year old PC game like half-life 2, so I would not worry as much. just make sure you don’t use too many rigid bodies, the rest can be straight moving projectiles Area3D/Raycast.
test your game on the target platform first, worry about optimization if it doesn’t work. make lots of tests, with different projects.
Thanks man, your first sentence was the answer I was looking for. I really appreciate it. I already have some hitscan guns in the game but was trying to find the most efficient way to handle projectiles.