Situation
I have three animations set in BlendSpace1D: idle, walk, and run, set at three
locations: 0.0, 0.5, and 1.0.
The duration of each animation is irregular.
What I want to implement
I want the animation movement and speed to be synchronized properly.
Version
OS: Windows 10
Godot: 4.5 C#
Animation Asset
URL (free version: Idle, Walk, Sprit): Universal Animation Library by Quaternius
What I’ve researched
There are various methods for using ChatGPT, including root motion, and I’ve tried them all, but I can’t find the right method.
Controller.cs
Implement and experiment with what you can do using AnimationTree
using Godot;
using System;
using System.Text;
namespace Player
{
public partial class Controller : CharacterBody3D
{
[Export] public AnimationPlayer animationPlayer;
[Export] public AnimationTree animationTree;
Vector3 direction = Vector3.Zero;
const float deadZone = 0.1f;
public override void _Ready()
{
animationTree.Active = true;
// tree.Set("parameters/move_blend/blend_position",0.0f);
}
float ApplyDeadZoneRemap(float value)
{
if (Mathf.Abs(value) < deadZone)
{
return 0.0f;
}
float sign = Mathf.Sign(value);
float magnitude = (Mathf.Abs(value) - deadZone) / (1.0f - deadZone);
magnitude = Mathf.Clamp(magnitude, 0.0f, 1.0f);
return magnitude * sign;
}
public void AnimationProcess()
{
GD.Print("Direction Length: " + direction.Length());
animationTree.Set("parameters/Move/blend_position",direction.Length());
}
public override void _Process(double delta)
{
direction = Vector3.Zero;
direction.X = Input.GetJoyAxis(0, JoyAxis.LeftX);
direction.Z = Input.GetJoyAxis(0, JoyAxis.LeftY);
/*
Basis camBasis = camera.GlobalTransform.Basis;
Vector3 direction = (camBasis.X * inputDir.X) + (camBasis.Z * inputDir.Z);
direction.Y = 0;
direction = direction.Normalized();
*/
direction.X = ApplyDeadZoneRemap(direction.X);
direction.Z = ApplyDeadZoneRemap(direction.Z);
AnimationProcess();
Velocity = direction.Normalized() * 1.0f;
}
public override void _PhysicsProcess(double delta)
{
MoveAndSlide();
}
}
}