Jamez0r

I'm working on a boss enemy, and I want his eyes to follow the player. I made an IK constraint for each eye-bone that targets a bone called player_position_bone. When I move the player_position_bone in Spine, the eyes follow it correctly.

Surprisingly, the only thread I found about this was this one: Is it possible to animate an IK target at runtime?

I've tried setting the player_position_bone's position (bone.setWorldX() and bone.setWorldY()) in numerous different places: before/after the animationState.update(), animationState.apply(skeleton), and setWorldTransform(). The only case that had ANY effect at all was to do it after the updateWorldTransform(), which would cause the player_position_bone to appear in the correct place on the player, but the eyes would still look towards the Setup Pose's location for the player_position_bone.

I also tried with/without an animation that keys the player_position_bone's position in case it was overriding anything by setting it back to the Setup Pose's location every frame.

How/at what point should I be setting the player_position_bone's location in order to have the eye-bone's IK constraint follow it? Should I be using bone.setWorldX/Y?

Thanks!!
Jamez0r
  • Сообщения: 84

badlogic

You have to set the bone position after animationState.update() and animationState.apply(skeleton), and before skeleton.updateWorldTransform(). The calls to the animation state update and apply the timelines of all active animations to the skeleton. The timelines might also affect your IK target bone, specifically its position. By setting the target bone location after those two calls, you override whatever effect the timelines had. You the call skeleton.updateWorldTransform() to calculate the final position and state of everything in the skeleton. This will take IK target bone position you set.
Аватара пользователя
badlogic

Mario
  • Сообщения: 2065

Nate

You need to adjust the local position of the bone. You can use Bone worldToLocal to convert world to local coordinates, but keep in mind a bone is positioned relative to its parent's origin.
Vector2 worldPosition, localPosition;
localPosition.set(worldPosition);
bone.getParent().worldToLocal(localPosition);
bone.setPosition(localPosition.x, localPosition.y);
Animations are also modifying local positions, so if you key the bone translation you'll need to make your changes after you apply animations.

When you call Skeleton updateWorldTransform it uses the local transforms to compute the world transforms and applies constraints. This is where you get parent bones affecting descendant bones, IK, etc. See here:
Runtime Skeletons - Spine Runtimes Guide
Аватара пользователя
Nate

Nate
  • Сообщения: 9241

Jamez0r

Thanks Badlogic & Nate for the explanations and example - setting the localPosition (rather than World) of the Bone just before updateWorldTransform() worked.

Also thanks for the behind-the-scenes info on whats going on with the animationState / skeleton. Makes sense now, and I'll read through that guide you linked :yes:
Jamez0r
  • Сообщения: 84


Вернуться в Runtimes