godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.53k stars 21.08k forks source link

Rootmotion track problem #95380

Closed CoyCatBlack closed 2 months ago

CoyCatBlack commented 2 months ago

Tested versions

Godot4.2

System information

Windows10-Godot4.2

Issue description

Hi, I am using godot4.2 and I am facing this problem is that my character cant rotate when he is moving 45 degree angle he should also rotate aswell, here is the video. Is there a way to fix this problem or that's how godot works. Btw I also animated the root to rotate when he is moving in 45 degree angle, is that the cause of it or I have found a bug??? {Open for suggestions} ThankQ

https://github.com/user-attachments/assets/1ee35419-d37a-4763-9951-1ed5bb964575

Steps to reproduce

Please do let me know if that was a bug or some issue in blender while I animated the root bone to rotate 45 degree angle so that the character should look at 45degree angle when I press forward and left or right button

Minimal reproduction project (MRP)

RootMotionProblem.zip

I have exported the models with animation properly enabled all the necessary stuff I am using godot4.2 i have the updated version in steam, so far it is the latest version, I have heard godot4.3 has come but it haven't came out yet in steam

AThousandShips commented 2 months ago

Please upload an MRP to help with testing this:

TokageItLab commented 2 months ago

It is the expected behavior and nothing has changed from the past. The root motion must be applied to any Node3D transform by extracting the transform values from the AnimationTree using get_root_motion_xxx after setting the root motion track. Read the documentation: https://docs.godotengine.org/en/stable/classes/class_animationmixer.html#class-animationmixer-method-get-root-motion-position

CoyCatBlack commented 2 months ago

Please upload an MRP to help with testing this:

  • A small Godot project which reproduces the issue, with no unnecessary files included. Be sure to not include the .godot folder in the archive (but keep project.godot).
  • Having an MRP is very important for contributors to be able to reproduce the bug in the same way that you are experiencing it. When testing a potential fix for the issue, contributors will use the MRP to validate that the fix is working as intended.
  • Drag and drop a ZIP archive to upload it (max 10 MB). Do not select another field until the project is done uploading.
  • Note for C# users: If your issue is not C#-specific, please upload a minimal reproduction project written in GDScript. This will make it easier for contributors to reproduce the issue locally as not everyone has a .NET setup available.

Should I give you tscn where there is character and animation???

CoyCatBlack commented 2 months ago

Please upload an MRP to help with testing this:

  • A small Godot project which reproduces the issue, with no unnecessary files included. Be sure to not include the .godot folder in the archive (but keep project.godot).
  • Having an MRP is very important for contributors to be able to reproduce the bug in the same way that you are experiencing it. When testing a potential fix for the issue, contributors will use the MRP to validate that the fix is working as intended.
  • Drag and drop a ZIP archive to upload it (max 10 MB). Do not select another field until the project is done uploading.
  • Note for C# users: If your issue is not C#-specific, please upload a minimal reproduction project written in GDScript. This will make it easier for contributors to reproduce the issue locally as not everyone has a .NET setup available.

here is my file RootMotionProblem.zip

CoyCatBlack commented 2 months ago

There is only bones of the rig that I can only select what do you mean about any node3d??

On Sun, 11 Aug 2024, 6:52 pm Silc Lizard (Tokage) Renew, < @.***> wrote:

It is the expected behavior and nothing has changed from the past. The root motion must be applied to any Node3D transform by extracting the transform values from the AnimationTree using get_root_motion_xxx after setting the root motion track. Read the documentation.

— Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/95380#issuecomment-2282768495, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWVWCWKOJQ4777TWUVJGYRTZQ5UCVAVCNFSM6AAAAABMKMDIQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBSG43DQNBZGU . You are receiving this because you authored the thread.Message ID: @.***>

CoyCatBlack commented 2 months ago

It is the expected behavior and nothing has changed from the past. The root motion must be applied to any Node3D transform by extracting the transform values from the AnimationTree using get_root_motion_xxx after setting the root motion track. Read the documentation: https://docs.godotengine.org/en/stable/classes/class_animationmixer.html#class-animationmixer-method-get-root-motion-position

This is tooo complicated 4 me, is there any other way where godot dev to fix this problem I mean just imagine the root bone is perfectly moving but why does it cancel the root bone rotation. I hope they fix in the latest update 🙏🙏🙏

TokageItLab commented 2 months ago

It is the same in Unity and Unreal that RootMotion will no longer play the Root bone animation directly. You must get the RootMotion as Vector3 or Quaternion from the AnimationMixer and add it yourself in a script to the transform of the any ancestor object of Skeleton.

Since root motion is a relative value, if you want to add root_motion_position, simply use the following expression like: Node3D.position += AnimationTree.get_root_motion_position(). It is almost same for rotation/Quaternion as Node3D.rotation *= AnimationTree.get_root_motion_rotation(), just applying general 3D math.

For the advanced case, if you want to blend multiple animations, you will need an accumlator, so refer to the code in the documentation.

CoyCatBlack commented 2 months ago

It is the same in Unity and Unreal that RootMotion will no longer play the Root bone animation directly. You must get the RootMotion as Vector3 or Quaternion from the AnimationMixer and add it yourself in a script to the transform of the any ancestor object of Skeleton.

Since root motion is a relative value, if you want to add root_motion_position, simply use the following expression like: Node3D.position += AnimationTree.get_root_motion_position(). It is almost same for rotation/Quaternion as Node3D.rotation *= AnimationTree.get_root_motion_rotation(), just applying general 3D math.

For the advanced case, if you want to blend multiple animations, you will need an accumlator, so refer to the code in the documentation.

If I use mixamo animation it is fine like it rotates the way it needs but if I use my custom rig with animation it does not work. If you see my video i did not even add a script but I use an animation tree node to blend the strafing animation if I apply the root to the rootmotion track it stops rotating but if I use mixamo animation then it works perfectly fine. I just hope the godot dev to fix this rootmotion track. Isn't there other way to fix this problem without a code???

TokageItLab commented 2 months ago

If you don't want to use the code, just apply the root rotation in DCC software such as blender to replace/convert the rotation track with a position track. Or you could create an ImporterPlugin in Godot to let the importer do the DCC work instead, to bake the first rotation key of the root track to position. In other words, current MRP animations aren't following the optimal workflow for creating animations when using root motion.

The root motion considers only delta. This is the intended behavior, since a rotation track with only one key has no delta in the rotation. If you do not want to change the animation, the accumulator must be handled in code;

Application process of the accumulators depends on the use case, so users need to apply the accumulators in any order they want. For example, whether the rotation is consistently global, consistently local, or a mix of the two and thus the order of calculations needs to be changed depending on the state, is dependent on the use case.

CoyCatBlack commented 2 months ago

If you don't want to use the code, just apply the root rotation in DCC software such as blender to replace/convert the rotation track with a position track. In other words, current MRP animations aren't following the optimal workflow for creating animations when using root motion.

The root motion considers only delta. This is the intended behavior, since a rotation track with only one key has no delta in the rotation. If you do not want to change the animation, the accumulator must be handled in code;

Application process of the accumulators depends on the use case, so users need to apply the accumulators in any order they want. For example, whether the rotation is consistently global, consistently local, or a mix of the two and thus the order of calculations needs to be changed depending on the state, is dependent on the use case.

In blender I will have to add another root bone and from that I can rotate my character, like this way. One root bone will be use to move the character and the other root bone I will name it (root.z) that will be use to rotate the character. I will export from blender to godot and if I assign the root bone (not root.z) to the rootmotion track hopefully that will work. I will update it once it work. Edit:

https://github.com/user-attachments/assets/7191a948-d3f1-4a04-b289-6906b8006a9d