What’s the best way to control physics properties for a whole group of rigid bodies at once (like an array of blocks).
Maybe place your objects in a list and then use a list iterator?
list = [obj1, obj2, obj3, obj4, etc...]
for obj in list:
obj.applyForce(0,0,1)
obj.name = obj.name+"!"
obj.mass += 1
<change other properties>
Python is pretty friendly when it comes to iterating lists or dictionaries.
Edit:
Yes, that is pretty much real Python in that code block even though it looks too simple to work.
The actual object properties I’ve used in my example might not even exist, but you should get the idea.
Enclose the items in the list in square brackets separated by a comma. You can also use list.append(obj5) to add to an existing list.
@FunkyWyrm - Yeah, I was going to say that you can’t change object names, but you’re right - that’s pretty much just how simple it is to change object properties with Python.
EDIT: Oh, but you can’t use obj.property for user defined properties - you’ll have to use obj[‘property’].
Good catch, SolarLune. I didn’t consider user-defined properties, ane it make sense that an object name is read-only at runtime. Getting my bpy/bge apis mixed up.
That way is how to do it for both properties assigned to an object at runtime and game properties that are defined in the logic editor. Only built-in properties are accessed how I showed.