+2 votes

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

in Engine by (698 points)

2 Answers

+2 votes
Best answer

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.

by (698 points)
selected by
+6 votes

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)
by (685 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.