Description
Godot version
v3.4.2.stable.mono.official
System information
Windows 10, GLES3, RTX 3060
Issue description
In the current state, root motion always returns a transform with the delta of rotation and translation.
This works fine for most scenarios.
However, when an animation has both rotation and translation, things get complicated.
It is necessary to save the orientation at the beginning of the animation, apply the translation relative to the saved orientation while rotating the object using the root motion delta rotation.
Example:
using Godot;
class Player : KinematicBody
{
private AnimationTree animationTree;
Transform orientation;
string state;
Vector3 inputVelocity;
public override void _Process(float delta)
{
Vector3 velocity;
var rootMotion = animationTree.GetRootMotionTransform();
if (state != "Turning")
{
orientation = GlobalTransform;
velocity = inputVelocity;
LookAt(inputVelocity, Vector3.Up);
}
else
{
velocity = orientation.basis.Xform(rootMotion.origin) / delta;
var rotation = rootMotion;
rotation.origin = Vector3.Zero;
GlobalTransform *= rotation;
}
this.MoveAndSlide(velocity);
}
}
This can work on animations where translations end up with no delta translation and small/zero xfade.
Otherwise, if the animation ends with some amount of delta and/or xfade, things will break.
Digging on the issues i found this PR #29458 that tries to fix that.
Which unfortunately appears to have been abandoned.
Steps to reproduce
Create a root motion animation only with translantion.
Create a root motion animation with translantion an rotation.
create one state machine that travels from one state to another.
applies thee root motion to the transform
GlobalTransform *= rootMotion;
Minimal reproduction project
Presse W to walk and A or D to turn.
Metadata
Metadata
Assignees
Type
Projects
Status