Scale an area2d based on distance?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Judd Gledhill
:warning: Old Version Published before Godot 3 was released.

Hi,

I have a simple projectile that is an Area2d with a sprite in it. I am moving towards a set position. I want to scale down based on how far along I am - 50% of the way there should be 50% smaller etc.

node.scale(Vector2(0.5, 0.5)) seems to be additive because my node (projectile) disappears quickly. What am I doing wrong here?

var percentleft = targetpoint.distance_to(self.get_global_pos())/initialflightdistance
self.scale(Vector2(percentleft ,percentleft))

I am thinking that I need some other approach, like a global scale. This call seems to be “additive” to the existing scale on the object? So I might scale to 90% then 90% of that 90% then 90% of that and so on.

Thanks,

Judd

:bust_in_silhouette: Reply From: kidscancode

This seems like the perfect opportunity to use a Tween:

Set the Tween to interpolate the transform/scale property.

I will look into that. Thank you.

Judd Gledhill | 2017-10-20 13:15

:bust_in_silhouette: Reply From: avencherus

You want to use set_scale() if you want to specifically set it, scale() applies the value against the current scaling.

So “scale” scales the value you already have, and set_scale is absolute then? That makes sense based on what I am seeing.

Judd Gledhill | 2017-10-20 13:15