Game Development Community

Handling a large number of objects

by Hilbert Reijngoudt · in Torque Game Builder · 06/02/2011 (1:37 pm) · 3 replies

I'm making a game in which each level contains a large number of enemies.
This all goes well until i turn on the collision callback on all the objects, everything gets really slow..

I think i should only enable the collision callback for the objects that are visible on screen, but i have no idea how to achieve that.

Anybody can help me with this?

#1
06/02/2011 (11:22 pm)
You can optimize collisions using the collision groups. Put all your enemies in a group (say group 1, it's just under the layer option) then set whatever is colliding with them to only collide with group 1 (that's in the collision settings) and vice-versa for the enemies so they only collide with the relevant objects. This will cut down on a lot of your collision calculations, however if you have a lot of objects (more than 100) all calculating collisions every frame you should expect some slowdown.
#2
06/03/2011 (2:12 am)
Thanks for the reply!!

I thought about putting the enemies in a group, but the problem is that i also want them to collide with each other. But they only have to be able to move once they are visible on the screen. That's why i thought maybe i could enable them once they are visible. But i have no idea how to do this.
#3
06/23/2011 (4:10 am)
It's been a couple of weeks since i worked on this issue. I've been busy with the implementation of other stuff.
But last week i got it to work and i thought i'd share it here, may come in handy for people with the same problem.

I'm making a game which has 1000+ objects in a single level. These all have to collide with each other and with the player too.
When i tried this i had a frame rate of < 1 because of all the collision detection that was done for all these objects all the time.

So i made a workaround, since i'm walking through my level it's not necessary that all objects are calculating collisions all the time. I Created a trigger and made it twice the size of my camera(just to be sure) and mounted that to the player.

All my objects are in the same group and have sendcollision and physics turned off(the receive collision is on) And when an object enters my trigger i turn on the physics/send collision and put it in the same group as the player. Once the object leaves my trigger i put it back to it's original group and turn the collision options off again(maybe in the future i'll delete them at this point since i can't walk back in my game)
So now the only objects that are calculating collisions are the ones that are inside my trigger. And now my game runs great again!!!! :-D

Just wanted to share this for people who are having the same problem.