I set parent of Mesh to Armature (with automatic weights).
Then I set parent of Armature to Empty, so that I can move the Empty and the whole armature/mesh thing moves.
This works fine, Ok.
The problem arises when I addObject( Empty )
The idea is to addObject(Empty) and let it automatically create everything,
because from what I have seen when you addObject an object, it also creates its children.
Now, what I want to do works, except that the mesh gets disconnected from the armature. The Empty is created,
the mesh is also created (you can see it) and the armature is created (because I reference it and even turn some
bones with code), but the mesh does not animate.
Its as if everything works except the armature gets disconnected from the mesh.
Skin is parented to armature, and contains a armature modifier [ no collision physics]
Armature parents to hitBox [ no collision physics]
hitbox is where you apply forces etc and move the agent, actions should happen ‘inside the hitbox’.
IE the armature should not jump, the armature should ‘jump while holding still’ and the agent hitbox should apply forces to jump.
to add a agent simply spawn a copy of hitBox -> hierarchy brings in the rest.
you can do
hitBox = own.scene.addObject('HitBox',own,0)
for child in hitBox.childrenRecursive:
if 'SkinTag' in child:
child.replaceMesh('SomeOtherMeshName',0,1)
I add the property ‘SkinTag’ so it’s easy to look up to replace mesh, or change color etc.
The problem is that the skin does not pose. It gets brought in, but does not pose.
Check the attached file that demonstrates my problem.
Go to layer 3, press play. The empty will add the hitbox (from layer 1), which will bring in the others.
But shouldn’t the doll have his arm up ? Like the original in layer 1 ?
The blue bracer shows that the armature has been brought in posed (with arm up). The blue bracer works, follows the armature Ok.
The skin does not work, it does not follow the armature.
It seems if I add an Armature -> Play actuator, it works. Just create a dummy animation to put in the actuator box, and play it from frame 0 to frame 0.
Then the CopyRotation contraint from the little cube is suddenly applied. WTF !!!
Since this a lucky result and am developing a rather large project here, perhaps someone could point me to some documentation, or explain what’s going on ? This is a crucial part of my next game and I need to understand what I am doing.
You bind the bone with bone constraint --> Copy Rotation to some object (e.g. a simple cube) and then with python rotate the cube =
mat = mathutils.Matrix.Rotation( math.radians(someAngleToRotateTheJoint), 3, 'Y')
cube.localOrientation = mat
Et voila! Just like that, you can animate cubes instead of bones ! I have tried it, it works.
You just need to call update( ) on the armature to see the changes. No logic bricks anywhere.
The thing is that when you spawn the whole thing, it does not work anymore. It needs actuators to fix.
I can not understand what is the difference between the spawned instance version and the “original” version.
Because they obviously behave differently.
It is not a so very important question for me anymore, because I will use the actuators from now on per your
suggestion. But if you feel like discussing why the spawned version is different, I am all ears.
I literally just spawn the armature into the current state and the object spawns with it?
EDIT:
It seems you can spawn any object with children and expect them all to spawn with the parent.
But the children you can’t expect the parent to be with it when you spawn them.