cpu/memory usage: Hitscan vs projectiles in a top down shooter

Hello there

Working on a top-down shooter I’ve been experimenting with both hitscan (raycasted bullets with instant hitrate) and projectile based shooting (bullets as gameobjects, with travel time).
Gameplay-wise projectile based shooting purely seem to hold advantages over hitscan shooting in a top-down shooter, but I have no clue how it affect performance.

Do projectile based shooting make the game more memory/cpu-heavy and if so is it by a lot?

I also imagine that one is better than the other when speaking of online play, when speaking of lag, cheating and so on.

Can anyone shed light on this matter?

Thank you for reading

Instant hit vs Projectiles is a game play issue and you should probably address that question before you consider the implementation and performance issues.

Do projectile based shooting make the game more memory/cpu-heavy and if so is it by a lot?

Yes, but a “lot” is very subjective. If its a bullet-hell type game with many hundreds or even thousands of active bullets this could potentially be a performance problem.

You should probably do some experiments that reflect as best you can the conditions of your game.

If performance is an issue you might want to consider a custom physics system. Unless you have some wild and whacky bullet types the physics should be pretty simple. Your own physics can be deterministic which will also help the online multi-player aspect of the game (player input will be the only aspect that wont be pre-determined so you just need a good mechanism to sync this).

Typically in this approach you wouldn’t need GameObjects, just store your projectiles in a custom data structure. For rendering you can tie the data structure to GameObjects, meshes or (probably best) particle systems.

All of that said work out your requirements first. There’s no point using custom physics and rendering if all you want a single player top-down shooter with a small number of projectiles.

I’ve considered the gameplay “issues” and as stated I only see advantages for projectiles, compared to hitscan…
IF bulletspeed could be set to extremely high (more or less instant), but by doing some testing, I’ve come across the problem of very fast bullets going through walls… I assume the collisiondetection isn’t fast enough/checking often enough, meaning that a few bullets here and there will pass through a wall…
If I slow down the speed, no problem, but with fast speed the pass through from time to time…

Back to hitscan, except for a few slower-projectile weapons then :stuck_out_tongue: