Godot Version
4.5
Question
I’m trying to get my 3d character to properly blend between animations, but I’m having some trouble getting it to work the exact way i want.
My goal:
Tha player characters movement should be “free” when not locked on to a target, meaning that the player should always use the forward running animation when not locked on to an enemy or other target (or when dashing or sprinting although they have their own animation)
The issue I’m having trouble figuring out is how to blend between animations when the player is locked on to a target.
I think what I need the blend value to be input_direction relative to the camera rotation? problem is that I’m not sure how to get that
the logic that the animations should follow is : when the player moves to either side the sideways running animation should play (and then the same for forward- and backward movement)
I don’t want to do just “if input then play animation” since the animations should blend smoothly between each other and I think this is a good learning opportunity
I got frustrated with it not working and chatgpt made this (i know it’s bad practice to use AI but it was never my intention actually use this or learn from it):
var local_vel : Vector3 = visual_model.to_local(visual_model.global_position + velocity).normalized()
It kind of works, although the values “snap” a lot (either it returns 1 or 0 )
I’m having a lot of trouble figuring this out, I haven’t really been able to find a tutorial either that explains it
Any and all help is appreciated ![]()
“full” code snippet :
func update_anim_tree_blend_param() -> void:
var local_vel : Vector3 = visual_model.to_local(visual_model.global_position + velocity).normalized()
var vec2_local_vel : Vector2 = Vector2(local_vel.x,local_vel.y)
print(vec2_local_vel)
#If not locked on, dashing, or sprinting, the player should have free movement
#ground movement
anim_tree["parameters/Ground_movement/blend_position"] = vec2_local_vel