SmartlyDressedGames / Unturned-3.x-Community

Community portion of the Unturned-3.x repo. If you have access to the source code you can find it here:
https://github.com/SmartlyDressedGames/Unturned-3.x/
84 stars 18 forks source link

[Preview Branch] Spine Parent breaks #4549

Open elsultaan opened 1 week ago

elsultaan commented 1 week ago

When parenting items to the spine, animating becomes a hassle because in-game the Item prefab will always be rotated 90 degrees on the z? axis. Ideally a Spine_Hook bone should exist that moves independently from the Spine, like the Right_Hook and Left_Hook bones for both hands. So people can move that around instead of having to animate the Item prefab's transforms, or adding an armature to the Item Prefab and vertex grouping parts of the item. The latter will cause even more problems for items like guns, because it will be necessary to add constraints to every attachment to make sure they follow the moving bone.

DerEnte commented 1 week ago

Same issue over here

https://github.com/SmartlyDressedGames/Unturned-3.x-Community/assets/80266096/394f3926-545f-4a19-ae66-1a09584362e4

SDGNelson commented 1 week ago

It will default to (0, 0, 90), but I'd think the animation would override the item transform's rotation. For the gun animation attached to the spine are you animating a child of the item transform?

elsultaan commented 1 week ago

We were both animating the Item's transforms/rotations because it seemed easier than having to animate the root bone of the item's armature itself. That would complicate things further because the attachments on the gun follow the item prefab and not the root bone of the armature.

elsultaan commented 1 week ago

image

This was happening to Der Ente's gun and my Brass Knuckles (as seen in the pic) earlier.

SDGNelson commented 1 week ago

Sorry, I'm not sure I understand. When you say animating the root bone of the item's armature, is that a child of the equipable prefab / item prefab? If you're animating the Item's transform does it have the 90 degree rotation offset in Blender as well?

elsultaan commented 1 week ago

When it comes to animating guns with moving parts, we always set up the item prefab in this way. The Blender hiearchy corresponds to the unity hierarchy. image

Item_SMG2 is the same as Instantiated_Item_Name_Override Item_SMG2.

When using the Spine Parent argument, Ente used a new bone with the same name as the Unity Item Prefab. That's the source of 90 degree rotation issue.

I managed to fix my brass knuckles with keeping the Item stationary at the location of the Spine bone. And animating the Equipped item's child armature, which will let me move each brass knuckle separately from the item's actual position. But this solution won't work for guns because every attachmenthook(grip, barrel, etc) will have to be parented to the root bone of the gun that we animate so it moves along with the gun.

This is why a Spine_Hook bone, would solve everything because it would work independently from the parent just like Right_Hook or Left_Hook without the need of treating the Item Prefab as a bone.

DerEnte commented 1 week ago

Personally, I copied one of the hook bones and rotated it and parented it to the spine and renamed it to "Item", afterwards I parent my entire weapon armature on it treating it as if it was an item prefab in unity. image In blender, the animation works normally as opposed to in unity, where the item prefab gets rotated 90 degrees, as seen in my previous comment. We tried various workarounds such as parenting an empty to the spine and having it copy transforms from the original hook bone, which resulted in Sultaan's example.

SDGNelson commented 6 days ago

It's been a while but I suppose those hook bones must have been added for a similar reason in the first place!

I'm not 100% sure how far-reaching the implications of modifying the base skeleton might be, so I'm hesitant to mess with this shortly before the update. I do think, however, that it should be possible to work around this using the EquipablePrefab option. Since it sounds like your gun contains a skinned mesh, this is already right up the alley of having a separate higher-detail prefab for the gun and a static mesh for the Item prefab.

If I'm understanding correctly, I think it might work for the EquipablePrefab gun to be aligned with however the animation is being imported into Unity, and in Blender to rotate the constrained model so that you can work on it normally. Does that make sense?

DerEnte commented 6 days ago

I honestly don't see how the EquipablePrefab can help with this, and also we have various bone constraints on the gun itself, so if we rotate the constrainted model, the constraints will react to those changes, thus we cannot export the animation normally while it is rotated.

SDGNelson commented 5 days ago

Could you email me one of your example cases, please? I'll see if I can find a workaround, and if not I'll have to add the new bone.

DerEnte commented 5 days ago

Bet

SDGNelson commented 5 days ago

Thanks for sending it! I wasn't quite sure about how the sub-item transforms were being exported, but for the root I wonder if this Forward: X, Up: Z, Apply Transform: Yes option works on your end? This was exporting the gun as a separate fbx with different settings than the character and putting the mesh directly on the "Item" bone. FBX Settings Animation

DerEnte commented 5 days ago

This does work on my end, but as soon as I add in the armature of the gun just turns 90 degrees, I had to double check 10 times that this does infact happen.

I think I could probably somehow connect the entire weapon armature to the player skeleton, this could work.

SDGNelson commented 4 days ago

Maybe the most feasible option is indeed an intermediary bone. I'll add it as a fourth option for attachment parent. :S

SDGNelson commented 4 days ago

Okay: There's a SpineHook option for EquipableModelParent on the preview branch now, but the bone is optional. You can add a bone named Spine_Hook to the Spine bone and it should work to have your item underneath that. 🤞

DerEnte commented 4 days ago

Ok, I will check it out tommorow

DerEnte commented 4 days ago

thank you

elsultaan commented 4 days ago

Thank you!

SDGNelson commented 4 days ago

You're welcome, no problem! Thanks for raising the issue before the update released. Hopefully it works OK - I will double-check in multiplayer this evening.

DerEnte commented 4 days ago

Works almost fine. https://github.com/SmartlyDressedGames/Unturned-3.x-Community/assets/80266096/ae18c6e3-f0d7-4a51-a0a4-6928c3ab9a30

DerEnte commented 4 days ago

also in 3rd person, it seems that the weapon isn't bound to to the hand. It follows the spine too well. image

DerEnte commented 4 days ago

although this seems to be a problem in blender as well

DerEnte commented 4 days ago

fixed it in blender by clearing the parents, the issue persists in unturned though.

SDGNelson commented 4 days ago

Oh crap. The reason is really dumb on my end. My sincere apologies for all the issues with this option which should have been rather simple! For the meantime I'm going to remove mention of it from the update notes until I can address it for the next update. 😞