This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

How can I set a node's translation to target's global translation using Godot's animation system. My hierarchies won't allow me to use local translation for the node. Here's a sample code which obviously doesn't work.

var temp = enemy.get_path()
var animation = Animation.new()
animation.add_track(0)
animation.track_set_path(0, str(temp)+":translation")
animation.track_insert_key(0, 0.0, enemy.translation)
animation.track_insert_key(0, 1.0, global_target_translation)
in Engine by (63 points)
edited by

Here is my "dirty" fix. I momentarily move the node to the target translation, save the local translation and then move it back.

var temp_save = enemy.global_transform.origin
enemy.global_transform.origin = global_target_translation
var local_target_translation = enemy.translation
enemy.global_transform.origin = temp_save

var temp = enemy.get_path()
var animation = Animation.new()
animation.add_track(0)
animation.track_set_path(0, str(temp)+":translation")
animation.track_insert_key(0, 0.0, enemy.translation)
animation.track_insert_key(0, 1.0, local_target_translation)

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.