Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ville |
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)
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)
ville | 2019-03-22 19:24