Gintong
January 19, 2025, 12:46pm
1
Godot Version
4.2.2
Question
Hey! I’m trying to change the speed of a car over time using a tween, but it’s not working. Here’s my current code:
var tween = create_tween()
tween.interpolate_value(speed, speed * Main.speed_mult - speed, 1, 2, Tween.TRANS_LINEAR, Tween.EASE_IN)
you might need pass delta value into it. Look up the delta in the godot manual.
Well, in case you didn’t know interpolate_value
doesn’t animate anything, it simply returns a value you can use to animate it manually, it works almost exactly as lerp()
and use it on _process(delta)
so you’ll have to do:
var elapsed = 0.0
func _process(delta):
elapsed += delta
car_velocity = Tween.interpolate_value(speed, final_speed - speed, elapsed, 2, Tween.TRANS_LINEAR, Tween.EASE_IN)
Which is just ewwwww…
However I fail to understand why not use tween_property
directly, on the car script call it like so:
var tween = create_tween()
tween.tween_property(self, "position", Vector2(100, 0), 2.0)
If you’re calling it from another script or parent, call it like so:
tween.tween_property($path/to/Car, "position", Vector2(100, 0), 2.0)
And modify the vector2(), or whatever you need to your pleasure.
1 Like