erosario

Hello.

We're considering purchasing the Pro version for the IK feature but we are investigating if we can access the IK constraints in Unity.

For example, an octopus created in Spine has three animations, idle, attack, and eat. The octopus remains "idle" swimming around randomly until an object enters within its greater perimeter. The octopus then activates its "attack" state and the tentacles would reach out towards the fish. As the fish flees, the tentacles (with the octopus body pulled along through IK) would continue "pursuing" the fish until the fish reaches a certain distance or is captured by the octopus eaten.

Is something like this possible?

Thanks!

E.
erosario
  • Сообщения: 5

Pharan

An IK Constraint at runtime is a Spine.IkConstraint object.
You can get it like this:
void Start () {
var myConstraint = GetComponent<SkeletonAnimation>().skeleton.FindIkConstraint("foot ik");
}
https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-csharp/src/Skeleton.cs#L290

I assume you want to control the IkConstraint.Mix to slide between 0 and 1 depending on your octopus's state.
https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-csharp/src/IkConstraint.cs

You would also need to set the target bone position.
void Start () {
var targetBone = GetComponent<SkeletonAnimation>().skeleton.FindBone("target bone");
Vector2 boneLocalPosition = new Vector2(50f, 30f);
// You need to use this.transform.InverseTransformPoint(worldPosition) to get this value.
// This is assuming your targetBone is an immediate child of the root bone, and the root bone is never moved.
targetBone.SetPosition(boneLocalPosition);
}
https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-unity/Assets/spine-unity/SkeletonExtensions.cs#L92
Аватара пользователя
Pharan
  • Сообщения: 5366

erosario

Thanks!
erosario
  • Сообщения: 5


Вернуться в Unity