@Abdo23 said:
This seems much more complicated than what I'm asking for.
What I want for example is simply to move an object from point A to point B but those points will be determined during runtime. And after that, I would like to do another animation like scaling the object and then call a certain function.
PS: Without using physics, lerp or coroutine. I'm talking about an "Animation" library.
Something like this, for example? (not tested, just an example)
extends Spatial
var anim_position_one = Vector3(0,0,0)
var anim_position_two = Vector3(0,0,0)
var anim_position_delta = Vector3(0,0,0)
var anim_position_percent = 0;
var anim_position_start = false
var anim_position_speed = 4;
func _ready:
start_animation(get_node("Node_01").global_transform.origin, get_node("Node_02").global_transform.origin)
func start_animation(position_one, position_two):
anim_position_one = position_one
anim_position_two = position_two
anim_position_delta = anim_position_two - anim_position_one;
anim_position_percent = 0
anim_position_start = true
func _process(delta):
if (anim_position_start == true):
anim_position_percent += delta * anim_position_speed
if (anim_position_percent >= 1):
end_animation()
anim_position_percent = 1
anim_position_start = false
global_transform.origin = anim_position_one + (anim_position_delta * anim)
func end_animation():
print ("Animation ended! Do whatever you need to do when the animation stopped here!")
Then you can pass in different positions into start_animation to change how the animation works. Granted, this is basically already what the Tween function does, but instead you are just making the functionality Tween provides yourself.
I've done code similar to this before when I am rapidly prototyping and I need to have more than one property change as the values change from one thing to another. However, a huge problem with code like this is it gets very messy. Each animation you want to have in code you will have to write the code to run it, and depending on how many animations you have, this can get overwhelming and complex in a very short time.
If you can, I would highly suggest using the AnimationPlayer node when possible. You can add function tracks to call functions when the animation ends. It is a little harder if you want to smoothly move from one changing point to another changing point, but in that case I would just use the Tween function, as that is what it's meant to do.
By using the AnimationPlayer node for your non-changing parts of your animation(s), and the Tween function for your changing ones, you can pretty much handle any animation simply by combining these together in various ways. For example, you can start function that will Tween the positions in _physics_process at the end of an animation in the AnimationPlayer node.
Hopefully this helps! :smile: