Animation from current value to specific value

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By timoschwarzer
:warning: Old Version Published before Godot 3 was released.

Hello Godot community!

Is it possible to have an AnimationPlayer playing an animation towards a value?
For example, I have my Camera2D with zoom at 1.7|1.7, then the Player should animate from 1.7|1.7 to 1|1 (if my keyframe is 1|1). And if the zoom is 0.6|0.6 it should animate from 0.6|0.6 to 1|1.

Best regards,
Timo

:bust_in_silhouette: Reply From: puppetmaster-

You can do it in code

1.get the animation

var start_anim = animationPlayer.get_animation("start_game")

2.find the track to change

var idx = start_anim.find_track("game/Camera2D:zoom")

3.change animation point

start_anim.track_set_key_value(idx, 0, startZoom)
start_anim.track_set_key_value(idx, 1, destZoom)
:bust_in_silhouette: Reply From: timoschwarzer

Using Tweens was the best and easiest solution for me

func animate_to(nodeOrPath, prop, to, length = 0.5, easing = 2):
	var node = makeNode(nodeOrPath)
	var tween = Tween.new()
	node.add_child(tween)
	tween.targeting_property(node, prop, node, prop, to, length, tween.TRANS_SINE, easing)
	tween.start()

func makeNode(nodeOrPath):
	var node = nodeOrPath
	if (nodeOrPath.is_type("String")):
		node = get_node(nodeOrPath)
	return node

The easing parameter has to be one of the EASE_*** constants.