I’m working on a destruction system, where any impacted cube splits into 8 smaller cubes.
Basically there’s a cube with a script running, calculating its acceleration from its previous and current velocities. when the ‘acceleration’ variable reaches a certain value, the cube adds a group instance, containing the eight smaller cubes.
To keep the smaller cubes moving in the direction the larger one was going, their initial velocities must be set to match the bigger one’s before it disappears.
But since I’m adding a group instance, I can’t access the eight cubes directly with
objectLastCreated (that accesses the group object). Instead, I have to go,
added = add.objectLastCreated for i in added.groupMembers: obj[str(i)].setLinearVelocity(own.getLinearVelocity()) obj[str(i)].setAngularVelocity(own.getAngularVelocity())
This affects all cubes that belong to the instanced group object. It works great when there’s only one cube breaking, but when there’s multiple cubes breaking, there’s multiple instanced groups being added. And all of them have the same name.
Thus, all groups are affected - regaurdless of the cube they came from:
As you can see, the cubes on the right change trajectory mid-course when the left lands. when velocity is set for one group of cubes, it resets all groups of cubes - because it’s the same group being added!
So my question is, how would I set velocity for one group instance, without affecting any others?
Here’s the .blend (made in UPBGE):
break.blend (996.6 KB)
Thanks for reading!