Facepunch / sbox-issues

175 stars 12 forks source link

[ModelDoc] Allow us to choose how an IK Chain swivels / pole target / hint direction #6084

Open Grodbert opened 1 month ago

Grodbert commented 1 month ago

For?

S&Box

What can't you do?

Currently IK chains use the first bone to choose which direction it's facing, this is pretty bad because if you think of your leg (strongest IK user), the way you bend your knee follows almost always the foot, which would be the last bone in the chain.

This makes blending dynamic animations very frustrating, as it follows the rotation of the pelvis, the root of the movement, it results in jarring and unnatural leg movement unless you do some workaround.

Example: (Look at the knees rotating with the pelvis instead of being straight like the feet)

https://github.com/user-attachments/assets/88fde888-0dfe-4637-b76f-cffa7cad4ea4

Normally, this isn't very apparent unless you have an eye for it, as the pelvis doesn't rotate as much as the spine; However, in our character, we only have the pelvis, which means it needs a lot of rotations to perform spine-heavy poses (like the punching shown above), otherwise, it would appear very stiff.

How would you like it to work?

I really suggest consulting with Max on this one, as he would be able to explain it better, but in synthesis:

Simplest solution would be having a dropdown in the IKChain node in modeldoc that asks how to orient the IKChain, being:

  1. Parent bone of chain (Default and current method, ex. Pelvis in a leg IK)
  2. Chain target _(It is common in animation to use the target to also orient, in a leg IK that would be "IK_FootL", a practical example would be looking at your knee standing up, see that it follows your foot rotating left to right.)
  3. Pole target *explained later

Another great option to have would be the option to add an angle offset to the chain, many times in Blender the chain is rotated 90° and needs to be corrected.

A pole in blender, or "hint" in unity, is a bone or attachment that the chain will rotate towards, usually for the leg it is parented to the foot as the foot and knee pretty much point in the same direction in most natural poses (as explained earlier with chain target). If this is not reasonable, I would at least like the implementation of the choice between 1 and 2, which would solve 95% of the cases.

Here is how it works in blender:

https://github.com/user-attachments/assets/9453d768-2ede-48fb-aa71-d4711aa3a735

Note the "Pole Angle" on the right, which would be the angle offset I've explained earlier.

Here is the descriptions of it in Unity:

unityhint

And finally here is a concept for how I think it could look in Modeldoc in the "IKChain" node:

concept In which the target source can either be an attachment or a bone, and the target bone can be either or none (use default IKChain behavior, as currently is). This concept art is a little older than some other features I explain in this issue. In this case the section would be named "Chain Orientation" or angle, containing a dropdown with the 3 options. If the last one is selected this section in the concept should appear. I also forgot to add "Pole Angle" in this concept, but it could just be a field you type a number into, none being the default.

I think this solution is ideal as it allows shrimple implementations like an attachment that's parented to the foot IK, or more conchplex ones for bones that are baked in the animation.

What have you tried?

These options in the "Two-Bone IK" animgraph node seemed promising. image But alas it didn't actually do what I wanted, no matter what combination I used.

The other solver types are worthless and don't add any other useful option (except dog leg IK, it was pretty useful in the past). image

"Alignment" doesn't seem to do anything as well. image

Additional context

Max needs to use a sort of benign workaround for the citizen: image

He said it caught him off guard and was the source for my testing image

Likewise, other users who came from other engines/programs notice instantly a lack of this option and are pretty bummed out to see there is no way to do it: image reputable source

Grodbert commented 1 month ago

I forgot to add a repro, LOL! models.zip Plop this in your project's asset folder and hopefully it's good to finagle. (updated 07/08/2024) Added pole bones so you can test the differences