0 votes

Hello there!

In my game I have a camera that is turns X degrees to the left, then X degrees to the right and repeat that. It rotates using an AnimationPlayer.

I'm trying to edit the camera rotation from code using an exported variable, so I can easily change it.I'm trying to do that using the following code:

extends Node2D

export(int) var max_rotation = 30

func _ready():
    var animation = $AnimationPlayer.get_animation("rotate")

    animation.track_set_key_value(0, 1, -max_rotation)
    animation.track_set_key_value(0, 2, -max_rotation)
    animation.track_set_key_value(0, 3, max_rotation)
    animation.track_set_key_value(0, 4, max_rotation)

It works but the animation becomes laggy (see this video). The first part of the animation, where it's not laggy, is when it's using the original animation value (if you did not notice, I changed the keys from 1 to 4, did not change the 0 key).

I already tried using float instead of int in the max_rotation and also tried adding the keys (using an empty animation) instead of editing their values but I got the same result. Also tried setting the autoplay on load in code instead of setting in the AnimationPlayer but the result was the same.

I ran out of ideas, can someone help me to get this fixed?

If you would like to test on your computer, here is the project on GitHub.

in Engine by (521 points)
edited by

Please log in or register to answer this question.

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.