This is a continuation of This topic. But I wasn’t able to play my animation even when I set the value and accessed the parameters. Does anyone have any suggestions for what I should do to fix this?
Code:
extends AnimationPlayer
@onready var animation_tree = $"../AnimationTree"
var score_change: bool = 1
@export var add_speed: int = 15
func _ready():
play("Idle")
func play_animation(delta):
score_change = lerpf(score_change,1,add_speed)
func update_tree():
animation_tree["parameters/Score_Change/add_amount"] = score_change
func _on_ball_paddle_collided(delta):
print("Ball Collide")
play_animation(delta)
Warning message I’m getting: scene/animation/animation_mixer.cpp:892 - AnimationMixer: 'Score_Change', Value Track: '.:rotation' has different interpolation types for rotation between some animations which may be blended together. Blending prioritizes angle interpolation, so the blending result uses the shortest path referenced to the initial (RESET animation) value. (User)
Any help would be appreciated, Thanks in advance .
Just for some more context since I was a little bit vague, Basically the Score number is supposed to make a little jiggle by turning from side to side while the idle animation is still playing. I used an Add2 to do this which was suggested @Monday (Thanks man!).
But the problem is, the animation plays fine in the animation tree, but when I set the Add2 value to 1, It doesn’t work or do anything. I know I’m doing something wrong here, but I just can’t wrap my head around what it is.
Odd types and values, bool should be set to true/false and I feel add_speed should be a float?
I am pretty sure you mean to get a float value range from 0 to 1 for score_change (not type bool). This lerpf use will give you some wild numbers, remember that lerp is a simple math function,
func lerpf(a: float, b: float, t: float) -> float:
return a + (b - a) * t
# taking score_change as 1 and add_speed as 15 your final equation is:
1 + (1 - 1) * 15
1 + (0 * 15)
(1 + 0)
1
I don’t know what values you want to get from this, I figure you probably want to reduce score_change to zero over time? You could use a tween then update the animation tree parameter, but I’d say it’s easier to tween the animation tree parameter directly
I’ll post a video on what issues I’m facing later, but could you quickly give me a reminder on what lerps and explain what tweens are? Might help me understand everything better.
Lerp is a math function, it calculates a value between a and b, normally using a range t between 0.0 to 1.0
If a = 5 and b = 20 I can get a value from 5 to 20 using t from 0.0 to 1.0 where t = 0.5 gives me the middle of the two values, 12.5
5 + (20 - 5) * 0.5
5 + (15 * 0.5)
(5 + 7.5)
12.5
It is an important part of animating but it does not animate or do anything over time by itself, just a short one-off calculation.
The tutorial you are following uses lerp as part of _physics_process, aside this should be _process, by using this every frame they gradually reduce, kind of like doing score_change -= 1 every frame. Using lerp every frame (even with delta) is a classic mistake and makes their animation frame-dependant and near impossible to control. They should be using move_toward, or tweens.
In your case you do not have a _process function and you do not need one! So a tween will serve you better.
A tween does animate over time, it’s a object in Godot and many other game engines. Notice how we have to create the tween before we can use it. It may be a good idea to store this tween reference in the class body, in case you need to stop or restart the tween/animation in-progress.
That explains everything a lot better! but I’m still confused on the tweens part. What do they do exactly? Tell me the same way you re-explained the lerp function to me
Every Node has the create_tween() function, this makes a tween object and binds it to the node; binding means when the Node is destroyed, so is it’s tween. The tween object is ready to store instructions and will try to operate them on the next frame.
The most basic instruction we can give a tween is to tween_property(). This instruction takes a property and gradually changes it to end_value over durations. This takes quite a few arguemnts:
the object to animate, it doesn’t have to be the binded object, but it usually is
the property path to animate, it needs to be a string for compiler reasons, but that works out for your animation tree just fine.
end_value; the tween must end with this value for the specified property
duration over how long the tween will animate toward end_value.
I add another instruction .from(), this sets the starting value.
Those two lines of code are similar to this long example object, not that one should make this object.
extends Node
class_name ExampleTweener
var object_to_animate: Object
var property_path: String
var duration: float
var starting_value: float
var ending_value: float
var elapsed_time: float = 0.0
func _process(delta: float) -> void:
elapsed_time += delta
var progress_ratio = elapsed_time / duration
if progress_ratio >= 1.0:
object_to_animate.set(property_path, ending_value)
self.queue_free()
else:
var new_value: float = lerpf(starting_value, ending_value, progress_ratio) # hey here's lerp!
object_to_animate.set(property_path, new_value)
func tween_property(object: Object, parameter: String, end: float, duration: float) -> void:
self.object_to_animate = object
self.parameter_path = parameter
self.end_value = end
self.duration = duration
It often uses the lerp function, because lerp means “linear interpolation” there are other interpolation modes you will want to check out. To change the interpolation mode use .set_trans(). Tween.TRANS_QUAD for instance looks good and is still a very fast equation, Tween.TRANS_SPRING will bounce past the end value and eventually settle, like a spring.
var tween := animation_tree.create_tween()
tween.tween_property(animation_tree, "parameters/Score_Change/add_amount", end, duration).from(start).set_trans(Tween.TRANS_QUAD)
Might take me a bit to fully understand the function of Tween, but just for the sake of this topic not being too long, could you tell me what I need to do to fix this issue with some explanation as well?
It works now! But the score rotates a little again before coming to a stop, how do I fix this?
And could you also explain how and where I could learn more about using tweens this way. And how can I access the play mode and modify it so the animation can also play backwards?
Seems like your AnimScore_Change doesn’t loop well, or needs to be a oneshot animation node instead of Add2 node. Which will require a different, easier triggering mechanism, one without tweens