Multiple playable characters resulting in low FPS (URGENT)

My game has multiple playable characters, which results in lag and low frames per second. I have a maximum of around 10 characters the player can control, each one of them at 2000 polys, and the fps drops to 20+, and makes the game function very slowly. The player controls them by clicking and sending a ray into the 3d world and they move to that spot. They switch characters by clicking on another character.

I have tried my best to reduce the number of polys of the in game models, but at this point in time, I’m hoping that the problems lie in the script itself.

Each of them have 2 “from” collisions when running around. One is the body collision, which prevents the characters from going through each other, and through walls. This uses CollisionHandlerPusher.
The other is the feet collision, which prevents the character from falling through the ground. This uses CollisionHandlerEvent, and a script that repositions itself to the ground all the time, and if it’s not colliding with the ground, if will keep falling until it does.

Heres the code for the 2 collisions.

Also, when they are in combat, another combat collision is attached to the sword of the character, but when it collides with the enemy, the collision is removed immediately. If it doesn’t collide, the collision node will be removed after the character’s attack animation is over.

I’m pretty sure the fall in fps is due to the collisions, as when I remove the body and feet collisions, the frame rate goes back up to 60.

Help is much appreciated. This problem needs to be fixed ASAP so that the game can be continued. Thanks in advance.

possible optimizations :

  1. use CHGravity instead of CHEvent to minimize Python function calls. Try my test scene in there :
  2. split your level into octree :

Have you created actual CollisionPolygons for the walls and floor collisions, or are you doing collide-with-geometry? Collide-with-geometry is way, way, slow, of course.

The call:


will light up collision polygons as they are being tested. If you see a lot of polygons lighting up, your scene is poorly structured.

You can run PStats to prove the problem is in the collision system and not somewhere else.