Flipping IK Handle Solver [UE4]

Discuss issues pertaining to the various game/web runtimes of Creature here.
Post Reply
Greywacky
Posts: 3
Joined: Sun Dec 06, 2020 1:36 pm

Flipping IK Handle Solver [UE4]

Post by Greywacky » Sun Dec 06, 2020 1:49 pm

I'm attempting to flip a character using the approach seen in the UE4 Bend Physics tutorial (https://www.youtube.com/watch?v=s0ClHd1HwBk&t=586s)
but the first bone in the IK handle retains it's orinial world position rather than move relative to the rest of the skeleton.

In this case it's an arm bone, so when flipped the character's shoulder is offset from torso, which is obviously not ideal!

I have tried removing the IK Handle before flipping then reapplying, which results in the same outcome.

I have also tried using the Bone Override function to translate the position of the bones, but once the IK is reapplied it again has the same problem, so it appears the issue stems from the IK solver.

There doesn't appear to be any way to set the sart postition in the CreatureBoneIK struct either - only the target position.

What exactly is the correct way to go about this?

chong
Posts: 1178
Joined: Thu Feb 19, 2015 2:21 am

Re: Flipping IK Handle Solver [UE4]

Post by chong » Sun Dec 06, 2020 11:37 pm

Hello,

In this case you will need more control than what the original plugin allows.
The IK solver is actually exposed for you in the code, you can take a look here:
https://github.com/kestrelm/Creature_UE ... .cpp#L1509

One thing you can consider is to not use the plugin's own IK implementation but rather:

1) Copy/clone the calc2BoneIKLambda function out to your own code base
2) Use the bone override function to completely override and control whatever you require
3) Modify ( you should be able to just call ) the calc2BoneIKLambda to run your own IK for your requirements.

Take note the IK solver computes relative to (0, 0). This means it assumes the first point of the IK chain is always at (0, 0) with everything relative to that. This means you just need to take that into consideration ( translate the base to (0, 0) first, compute IK solution, then put it back as an offset )\

Update: I also suggest you take a look at how the positions are extracted from the bones for the current IK approach here:
https://github.com/kestrelm/Creature_UE ... .cpp#L1725

Feel free to copy/clone the code and modify it for your own purposes. Notice how it extracts the bone positions and then runs the IK.

On additional idea is to run the IK before flipping first in the unflipped space, then flip. So the IK handle is always "unflipped" ( you need to take the target world space point, then unflip it to the character's facing space, run the IK, then flip the character ) since IK runs in the unflipped configuration.

Thanks

Greywacky
Posts: 3
Joined: Sun Dec 06, 2020 1:36 pm

Re: Flipping IK Handle Solver [UE4]

Post by Greywacky » Mon Dec 07, 2020 7:35 pm

Your advice is greatly appreciated, and I had suspected that it might be beyond the out of the box IK solver's capacity.

On your additional idea - I had already tried mixing up the order of operations a little, but perhaps I'll try tackling that angle again armed with your insight and see where that gets me.

If that fails, then I suspect I won't have a big enough time slot until the weekend (seems like the type of thing I'll want to take on in one session!) to try to implement your initial solution, but I intend to post my resulst either way afterwards.

Greywacky
Posts: 3
Joined: Sun Dec 06, 2020 1:36 pm

Re: Flipping IK Handle Solver [UE4]

Post by Greywacky » Tue Dec 15, 2020 8:12 pm

Using your advice I have come across a solution and though I'm not 100% happy with the approach (I'd rather a cleaner, less invasive way to do it), it does appear work.

I'm feeding an "offset" value into UCreatureMeshComponent::ComputeBonesIK via a variable I added to the FCreatureBoneIK struct.
The offset itself will have to be handled by each instance of my custom creature animator class (which also handles flipping, aiming etc).

When the character is flipped I amend the offset value and call RemoveBluePrintBonesIKConstraint before recalling SetBluePrintBonesIKConstraint with the new offset value which is in turn added to the start position first bone in the IK chain.


It did occur to me to try something a little more crude - align the start of the first bone in the IK to zero on the X axis in the Creature editor.
There are a few issues with this that I can see, however, and the first is that there doesn't appear to be a way to perfectly align the bone with the axis within the Creature Editor.
Secondly, any animation or modifications applied to parent bones would also going to offset the IK bone.
Finally, it's not a particularly versatile solution, but if it is a suitable solution to anyone else having similar issues, then I recommend considering it.
Of course, this solution will also fall flat should you require multiple IKs that the start of which do not align on the axis!

Post Reply