• Unity
  • Manipulate Path Constraint Via Script

Hi, I have a cool monster with a path constraint controlling his head and neck.
I'd like the neck and head to aim in an arbitrary direction, controlled by code (and the player).

I've used skeleton utility bone scripts to move bones around


it's great!
How can I grab pieces of the the manipulators in a Path Constraint to do something similar? Moving the manipulators via Script in Unity, to change the head direction dynamically?
Thanks!

Related Discussions
...

Glad you like it!

You would typically have a bone at the middle of the path that can be moved around as usual, as the Stretchyman Spine project shows.

Okay, in the stretchyman skeleton, I can see there are path constraints, that are connected to IK constraints, that are connected to bone targets.
In that example, in script code, I could move the bone that would move the IK, that would move the Path constraints.

  1. Is that the idea? Or did I miss how works?

2 .But there's not way to grab the manipulators in script for a Path constraint?

Sure, you can manipulate the vertices in a path attachment (not the path constraint).
PathAttachment vertices
Note a path is an attachment and all attachments are stateless and shared across skeletons. If you change the path attachment vertices, it will affect all skeleton instances. If you only have one skeleton using the skeleton data then that doesn't matter for you.

Another way to do it is to weight the path to bones, then move the bones. This doesn't have a problem with multiple skeleton instances, because each has their own bones. It is also usually pretty easy to position a bone in your game. Manipulating vertices is different if your path has weights.

Note you may not need IK constraints like stretchyman. A bone for each path vertex may be sufficient.

Depending on the movement you need, you may be able to use an animation. Eg, your animation could be with the neck all the way stretched, then you can blend the animation from 0 to 100% using TrackEntry alpha.

Thanks.
Yeah, I'm starting to think I would want that animation blending method. Having it track from 0 to 1, across an animation may be best.