0 votes

What is the difference between these two? Just where it gets and sets the initial and final values? Why would i use one over the other? Or these targeting functions do something different?

https://docs.godotengine.org/en/stable/classes/class_tween.html#class-tween-method-targeting-property

targeting_property

Animates property of object from the current value of the initialval property of initial to finalval for duration seconds, delay seconds later.

interpolate_property

Animates property of object from initialval to finalval for duration seconds, delay seconds later. Setting the initial value to null uses the current value of the property.

var t := Tween.new();
add_child(t)
t.interpolate_property(c, "position",
    c.position, Vector2(c.position.x + 200, c.position.y), 3.333,
    Tween.TRANS_LINEAR, Tween.EASE_OUT, 1)
t.start()

==

var t := Tween.new();
add_child(t)
t.targeting_property(c, "position", c, "position",
    Vector2(c.position.x + 200, c.position.y), 3.333,
    Tween.TRANS_LINEAR, Tween.EASE_OUT, 1)
t.start()

It is just so that I can pass in c, "position" instead of c.position?

Please and thanks.

Godot version 3.4.3
in Engine by (1,884 points)

1 Answer

+1 vote

I think the key point is did your object have a specific target object or not.

For a simple example, Suppose in a RPG game, we have a player and the player has a pet. When the player stands on the ground and when call out the pet, the pet will appear and randomly move from player's position to around. Since the pet has a target(the player), then for this pet, we can use function targeting_property like this following:

randomize()
var player: Object # the target object
var pet: Object # the object work with tween
var rand_vec = Vector2(randi()%200-100, randi()%200-100)
$Tween.targeting_property(pet, "global_position", player, "global_position", player.global_position + rand_vec, 2.0, Tween.TRANS_LINEAR, Tween.EASE_OUT_IN)

P.S. Above codes is just an idea, I don't really test it.

Then the pet will move from the player's current global position to a random place near the player.

So, If the object don't have any specific target object, or the target object is itself, then I will perfer to use function interpolate_property.

by (526 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.