- 已编辑
Bow Aiming
I have a few questions regarding setup in Spine and also in Unity.
What is the proper setup in Spine for our animator to allow for Walking and aiming a bow?
In spine I assume we need a bottom half only walk animation playing on track 0 and also know that they are trying to do a bow attack and play that on track 1?
If that's correct, what IK or other means do we need to make the arms point at the target and what is done in unity in the hierarchy? I assume we move an aiming bone of some sort towards the mouse and can lock it at -45 to 45 angles or whatever we decide in our game.
Thanks.
This depends on your what look you're after, what kind of structure the skeleton has and what the animations you want to be like
I think:
(1) You can have one walking animation as the base, or a plain walking version and an aiming-and-walking animation version.
(2) Have a second aiming animation, where you have the character's upper body aiming with the bow, and the direction is aimed using an IK target. The shooting animation is also probably similarly constructed. In these animations, don't key any of the leg parts. It's designed to go on top of the walking animation and any keys here will override the values of the walking animation.
(3) To make it really simple (and the calculations performant), the IK target should be a direct child of the root bone, and you shouldn't rotate or translate the root bone in any animation. If this is the case, the code below works.
(4) play and manage the walking animation on track 0. shooting and animing on track 1.
(5) control the IK target bone by keeping a reference to it, and subscribing to SkeletonAnimation's UpdateLocal event to set its position.
skeletonAnimation.UpdateLocal += HandleSetBonePosition;
and the method would look something like this:
void HandleSetBonePosition (ISkeletonAnimation s) {
if (isAiming) {
Vector2 targetPointLocalSpace = skeletonAnimation.transform.InverseTransformPoint(targetPointWorldSpace);
myIkTargetBone.SetPosition(targetPointLocalSpace); // This is an extension method. You can find it in SkeletonExtensions.cs.
}
}
The trick is mostly in the Spine rig. You need to set up your IK so the pose is correct when the IkConstraints are enabled.
Then just set the IkConstraint mixes to 1 in the relevant animations. Or control the IkConstraint.Mix value programmatically.
Very quick and informative thank you Pharan This makes complete sense on the Unity side of things.
I know the answer is an easy one, but would you suggest buying the IK gunman asset so that we can get a better idea of what to do on the spine side? I don't think either of us on the team quite understands how to force the shoulder and "aiming bones" to point at something constantly, so if we get that part then the above makes complete sense to me (programmer).
I think I can sum up the setup in a few bones.
You should be able to get the gist of it. (no images here. alignments are super specific to how you stylize your characters.)
This was fun to figure out, but it's standard stuff for 3D skeletal rigging people (which I am not). Make sure you turn bones visibility on in the Options box.
Way more than I expected, look forward to showing off some results in here some day of our game. Thanks again Pharan, hopefully that should be plenty to get us going... if not, well there's no hope