physics optimisation

For awhile now I’ve been developing a game within the blender game engine. In said game there are occasionally sequences with in which there are alot physically enabled objects (or just objects in general), and consequently this causes said game to lag. I was wondering if there were a way to allow the game engine to be more forgiving in terms of how much it can handle without having to bury yourself within the coding of the engine.
Here is a video link to said game… https://www.youtube.com/watch?v=7EuMaVAmwto

use a system to loop through the items with physics and deactivate if active.

so the whole script is*

import bge
cont = bge.logic.getCurrentController()
own = cont.owner

if 'PhysicsList' not in own:
    own['PhysicsList']=[]
    for objects in own.scene.objects:
        if 'Phys' in objects:
            if objects.getDistanceTo(own)>50:
                own['PhysicsList'].append(objects)
                objects.suspendDynamics()
                objects['Physics']=False
            else:
                own['PhysicsList'].append(objects)
                objects['Physics']=True


#this runs each frame
for objects in own['PhysicsList']:
    if objects.getDistanceTo(own)<50:
        if objects['Physics']==False:
              objects.restoreDynamics()
              objects['Physics']=True
    else:
        if objects['Physics']==True:
             objects.suspendDynamics()
             objects['Physics']=False

you could probably optimize if further by storing the property[‘Physics’] inside the list like this
[ [object, physics],[object1, physics],[object2, physics] ] etc.

I’m not sure I fully comprehend any of this. So it disables objects that are inactive?

1 Like

suspendDynamics() = turn off dynamics,

so if dynamics are on, and the object is more than 50 units away disable physics,

you label any item you want affected by the system with a property ‘phys’

I’m already using a system like that, thanks anyway though.

teach me how to use it please