Godot Version
v4.4.1.stable.official [49a5bc7b6]
Question
Hi, I’m new to the forums, thanks in advance to anyone checking this post out!
I’m a beginner to Godot and I started setting up a 3D character. I’m using the AnimationTree feature, so far I’ve got a character walking, jumping and punching with controller & mouse input. I’m using ‘Enable filtering’ to separate legs from upper body animation – the punches are controlled in the transition and the walking is in the statemachine.
THE PROBLEM:
is with the blending of the punch animation and controlling the blend amount with some time, smoothing or duration of some kind. The problem is in
‘animation_tree.set(“parameters/Blend2/blend_amount”, value_of_blend2towards)
I’m unable to interpolate the blend_amount smoothly.
The Blend2’s blend_amount is accessible in the inspector and easy to change the sliders value manually. I’ve also managed to access it through code but I’m unable to wrap my head around how to make the blend_amount interpolate from 1 back to zero using some kind of duration based in time or frames, or a delay, countdown or something to that effect.
Now, anytime the character punches, the upperbody freezes in the final/first frame of the punch loop and never interpolates back to the idle/walking.
I’m trying to achieve a smooth wind down where shortly after the punch concluded it starts blending/resetting back to zero inside the Blend2’s blend_amount.
I have tried various ways to make it interpolate without success
There’s two scripts associated to the character;
one holds the control inputs including physics_process (terrible_monster_fbx_to_glb_all_anims.gd)
and the other the animations of the character (player_3d.gd.)
Any help is greatly appreciated.
Here’s the code (problem is in func punch(delta):
extends Node3D
var t = 0.0
var frames_between_trigger: int = 120
var frame_counter: int = 0
@onready var var_special2 = get_parent().reference_speed
@onready var animation_tree: AnimationTree = $AnimationTree
#(my addition first row below)
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var state_machine : AnimationNodeStateMachinePlayback = animation_tree.get("parameters/StateMachine/playback")
@onready var transition_thingy : AnimationNodeTransition = animation_tree.get("parameters/Transition")
#@onready var state_machine : AnimationTree = animation_tree.get("parameters/StateMachine/playback")
@onready var move_tilt_path : String = "parameters/StateMachine/Move/tilt/add_amount"
@onready var _mesh: GeometryInstance3D = %Terrible_monster_fbx_to_glb_test3/Character1_Reference/Skeleton3D/polySurface71
@onready var _mesh2: GeometryInstance3D = %Terrible_monster_fbx_to_glb_test3/Character1_Ctrl_Reference/Character1_Ctrl_Hips/MAIN_Controll_TAIL_nurb/Armature/Skeleton3D/TAIL
var run_tilt = 0.0 : set = _set_run_tilt
func _ready():
get_parent_node_3d()
func _set_run_tilt(value : float):
run_tilt = clamp(value, -1.0, 1.0)
animation_tree.set(move_tilt_path, run_tilt)
func idle():
state_machine.travel("Idle")
animation_tree.set("parameters/TimeScale/scale", 0.5)
var_special2 = 1.0 if var_special2 > 1.0 else var_special2
print("var_special2 first", var_special2)
func move():
state_machine.travel("Move")
animation_tree.set("parameters/TimeScale/scale", abs(var_special2))
print("var_special2 ", var_special2)
func land():
state_machine.travel("Land")
func jump():
state_machine.travel("Jump")
func punch(delta):
#TRY move_toward() for interpolation from one value to another with delta
t += delta * 0.4
frame_counter += 1
#var x : float = lerp(animation_tree.get("parameters/Blend2/blend_amount"), 1.0, 0.1 * delta)
var value_of_blend = 0.0
value_of_blend = 1.0#delta * 1.0#Interpolation = A+(B-A) * t 0.0(1.0-0.0)*40.0
var value_of_blend2towards = move_toward(0.0, 1.0, 1.0)#delta)
print("Did we PUNCH??")
animation_tree.set("parameters/Blend2/blend_amount", value_of_blend2towards) #THE BASE ONE!!!! 1 1 1
#print(x)
#animation_tree.set("parameters/Blend2/blend_amount", float(x))
#animation_tree.set("parameters/Transition/transition_request", "state_2")
animation_tree.set("parameters/Transition/transition_request", "state_0")
#animation_tree.set("parameters/Blend2/blend_amount", 0.0)
if frame_counter >= frames_between_trigger:
animation_tree.set("parameters/Transition/transition_request", "state_1")
frame_counter = 0
print("Counter reached ")
func _on_player_3d_reference_speed_2(value: Variant) -> void:
var_special2 = value
pass # Replace with function body.


