- Змінено
[XNA] Moving a bone
I'm sure this is a simple question for most to answer -
All I'm trying to do is to move a bone in my code, but I cannot seem to get the bone to update its position while an animation is playing. As soon as an animation stops playing, it seems to work fine.
All I'm doing at the moment is setting the Bone.X and Bone.Y
trajectory.Y += Gravity * gameTime;
var location = new Vector2(Bone.X, Bone.Y);
location += trajectory * gameTime;
Bone.Rotation = rotation;
Bone.X = location.X;
Bone.Y = location.Y;
Bone.UpdateWorldTransform(false, false);
and then later on when the character updates I have the following:
AnimState.Update(frameTime);
AnimState.Apply(skeleton);
skeleton.UpdateWorldTransform();
bounds.Update(skeleton, true);
What am I missing? Any help appreciated!
Urgh.. nevermind.. think I figured it out. I was modifying the Bone instead of the BoneData. Seems to work fine now!
Sorry, guess spoke too soon. The above works fine for setting the bone position relative to its parent, but I want to set the world position of a child bone, without its parents transforms. Looking through the forums I can't see any info on how to do this with XNA, so would really appreciate the help. Matrix stuff isn't my strong point..
Is it a feasible option to make that bone (and the hierarchy and images under it) its own skeleton?
You could maybe hide the images in the main skeleton and show the separate skeleton when you need to.
Simpler positioning this way? And it might make better semantic sense even if it's just occasionally a separate object.
It is an option, although I'd prefer a solution that doesn't involve creating new skeletons. The original idea was just to pass any bone into my particle system so I can have enemy limbs flying off in any and all directions, applying gravity etc. If I had to create skeletons for each bone that I wanted to cut-off, it would involve a lot of extra work to do so.
I know it involves getting the inverse matrix transforms for the parent bones, but I can't see how to do that in XNA, I can only see the matrix proprties like M01, M11, and I have no idea how to create a Matrix from those..
Oh, you just wanted to explode the character.
I would definitely do this by making each fragment its own entity.
But whatever.
I wish I could help you out with matrix math.
The math to go from a world position to a bone's local position is discussed here:
viewtopic.php?p=12369#p12369
Thanks for the link, I checked out that page but couldn't figure out how to get the values into an XNA matrix. I'll take a closer look, maybe XNA has a Matrix3 class or something.
Cheers
Did something happen to the forum's code formatting? I saw color-formatted code yesterday but now the boxes are just short, wide, empty, gray rectangles.
Should be working now, you might need to refresh. Much fancier syntax highlighting! 8)