# Weird blender game engine python problem

I was trying to create the illusion of a building being destroyed as soon as there is a collision using python. Everything seems to work fine when I use a cube, but it breaks as soon as I use the real building

I have attached a simple version of the problem which illustrates both the cube and the building. Whenever the "player" cube collides with the red cube, the addobject works perfectly. The same thing done with a building produces weird results. (Note they have the exact same settings and they both use the same python module)

Can someone please help me resolve this mystery. I have been cracking my head for ever. Here's the blend file (Use the arrow keys to move the player cube and collide it with different objects) https://www.dropbox.com/s/q3gajcxasv1c2dt/break_demo.blend?dl=0

If anybody is stuck with a similar problem, then look into scaling. Here's my final code to get it done without using any empty's and rescaling in fly

def decimate(cont):
self = cont.owner
scene = self.scene
self.scaling = [1,1,1]
self.endObject()


Also if it seems that the object gets added, but at the wrong location. Then it is due to the fact that the origin is not set. Try to set the origin to center of geometry or center of mass (Ctrl + Shift + Alt + C). You have to set this by selecting the empty associated with the group. Look at this question for more details Replace objects with a group of objects using Python

• Please show your code separately, and preferably use a simple-as-possible blend. Also, some screenshots couldn't hurt. Help us help you :) – Greg Zaal Oct 28 '14 at 6:26
• Do you want to do it with code? There are other ways of doing it , Like , use the fracture tool , And fracture your object . Then when you dragon is colliding use a rigidbody on the object , then depending on the speed it will break and look realistic – Knuckles209cp Oct 28 '14 at 9:08
• Yes a code is preferred cause I have like 90 objects and would end up adding different constraints – chettyharish Oct 29 '14 at 5:54
• I made a simple code example which still illustrates the point – chettyharish Nov 2 '14 at 4:54

There is one notable difference between the cube and the building -> The cube has a unit scale (1, 1, 1), but the building is scaled down. Since spawned objects adopt the local scale of the spawner, the behavior you observe, while not desired, is perfectly normal.

To get desired behavior, you need to specify a spawner object (typically an empty) with a unit scale, and use that to spawn the relevant group.

So, the script would now look like this:

def decimate(cont):
self = cont.owner
scene = self.scene
spawner = scene.objects["Spawner"]
spawner.worldPosition = self.worldPosition
spawner.worldOrientation = self.worldOrientation