Facepunch / sbox-issues

176 stars 12 forks source link

A way to retrieve the animation controlled transform when a bone is procedural #6533

Open yuberee opened 2 days ago

yuberee commented 2 days ago

For?

S&Box

What can't you do?

When a bone is marked as procedural, there is no way to get the animation controlled transform of the bone, as now it will only return that bone's current transform.

Being able to retrieve the bone's original transform would open up many possibilities such as active ragdolls, manual inverse kinematic for walking on rough terrain, physics based characters etc...

How would you like it to work?

if ( renderer.TryGetBoneTransform( "arm_upper_L", out var transform ) )
    Log.Info( transform );
Log.Info( renderer.GetBoneObject( "arm_upper_L" ).Transform.Position );

These are the only ways to get a bone's transform right now, perhaps the addition of SkinnedModelRenderer.TryGetBoneAnimationTransform or some sort. Ideally both the local and the world transform would be provided, but we only really need the local transform as the world one can get messy if we want to do a combination of procedural and animated bones.

What have you tried?

There's an ugly workaround for this but it doesn't always work, basically you create two skinned model rendererd with the same model. One gets assigned as the "puppet", basically the ragdoll, and the other gets assigned as the "puppetter", which will be animated normally. We hide the puppetter and copy each bone's transform over to the puppet every frame, when we want to ragdoll we stop copying the transforms and parent the puppetter to the puppet, when we want a physics based character we apply forces to the puppet's bones to follow the puppetter's instead of setting them manually.

That's inconvenient and doesn't work well in multiplayer.

Additional context

Here's how I'd use it for the examples I've given: