The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+3 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,

in Engine by (713 points)

2 Answers

+3 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.targeting_property(node, prop, node, prop, to, length, tween.TRANS_SINE, easing)

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 (713 points)
selected by
+8 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 (699 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 Frequently asked questions and 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 [email protected] with your username.