Survival Game Performance Issues

I am making a wave survival type of game in playcanvas; There is a simple square map with a few obstacles, character that is able to shoot, and waves of enemies, each new wave includues more enemies. Enemies are quite simple - they just follow the character and hit it if close enough. The problem is the enemies quantity and physics. The only way I found to make enemies follow the character while colliding with obstacles and each other is using physics (collider + rigidbody). However, when there are many enemies at the same time, fps starts dropping severely even on my modern laptop. Is there any way out of this? Any optimization that would allow to keep dozens of enemies moving while not destroying the CPU?

Hi @Dmytro_Khudiiash,

How exactly are you moving your enemies? Are you doing raycasts to check their hits against the player?

Most likely your slowdown is coming from that. Try profiling your code to find the exact part that is the issue.

Ways to improve that would be to run your raycasts in a lower interval, not per frame but e.g. a few times per second only.

As for moving the enemies, I simply find direction towards the player and teleport the rigidbody in that direction. As for checking hits with the player, I don’t use raycasting, I just check for collisions using ‘collsiionstart’ event.

Do you mean the playcanvas profiler or chrome’s dev tools profiler?

Both, the PlayCanvas profiler will show you the CPU total time which can be useful to monitor. The Chrome dev tools can show you a more detailed view of how your code performs (search for a tutorial online).

1 Like