targeting_property vs interpolate_property

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rakkarage

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?

targeting_property

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

interpolate_property

Animates property of object from initial_val to final_val 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.

:bust_in_silhouette: Reply From: ponponyaya

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.