It's time to go to bed object!

I hope this is a simple question but I cant figure it out. Is there python code i could use to make a dynamic object sleep, somthing like:

own.GOTOSLEEP()

I want dynamic objects but i dont need them to be active untill somthing hits them so i want the game to start with them sleeping. Point is to have dynamic gates and walls that dont take up much prossessing power untill a player hits them.

thanks in advance :slight_smile:

obj.suspendDynamics()

simple example, that makes all objects with property “dynamic” to “gotosleep”:


try:
for obj in some_object_list:
		if obj.has_key("dynamic"):
			obj.suspendDynamics()
except: pass


Unless you have a lot of dynamic gates or walls, there’s no need for this as the BGE will make them sleep eventually. Also, gates and walls should not be dynamic.

to haidme:

I dont want to uses suspend dynamics becaus thats more like puting them in a coma. I want them to wake back up dynamicly just like when they fall asleep dynamicly. if youve ever watched a dynamic object with “show physics visualzation” on you will be able to actualy see the objects fall asleep and wake back up dynamicly. this is what i want to happen but i want the objects to start sleeping rather than starting awake. in other words i do not want them to calculate physicts untill hit by another dynamic force.

to joeman:

normaly yes however, I am atempting to create a fully destructable world for cars to smash through. Im shoting for somthing like redfaction gurrila

Why not use a collision sensor to manually suspend/resume physics? if collision: restore dynamics… simples! :smiley:

That might work, Ill need a way to suspend them again after a sertain durration of time, is there a way to get a script to count or somthing, like after 10 tics go back to sleep?

Ok that didnt work, while suspended the objects dont detect collison and thus never wake back up. Let me ask this then, is there a way to change a sensor object into a dynamic object in game? that would solve the problem, since all the objects could be sensor object and only become dynamic when nessisary.

What you need to do is let say player.getDistanceTo(suspendedObject) then change the object stance rather than using collision sensors to the suspended object.
I use suspend/restore dynamics of many object in my game…ex: The player go near to a barrel(there are many objects on top of the barrel) ,the player break the barrel…objects falls down and starts rolling.
Reference:

Is this what you want to achieve?

Yes and no, because of the sheer volume of entitys involived (somtihng like every brick 2x4) if the objects became dynamic baced on procimity it would bog down the computer. if however the objects were static, or sensor objects the converted into dynamic only when hit by the players weapon, only the nessisary objects would become dynamic, as oposed to the etire building.

Pleas tell me there is a script to go obj.setobjectdynamic() and obj.setundynamic!!!

to get the effect I want i think converting static objects into dynamic in game is the bes solution, there must be a way to do this.

Haidme, in your first post here there was a way to detect the the objects key or somthing, dosen’t that mean there should also be a way to write to that value?