Make player (kinematicbody2d) scale up and down when moving up or down.

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

I need some help with my player that is supposed to scale down as it moves up (as it is getting far away from location) and scale up as the player comes back. Can anyone help?

:bust_in_silhouette: Reply From: Spyrex

Use the scale property of the KinematicBody2D to scale it.
To get the value to scale to, you can use the distance_to ( Vector2 ) method of the Vector2 class and make it negative, to scale down on higher distances and vice versa.
Example script of the kinematic body:

func _process(delta):
    scale = -(ORIGIN_LOCATION.distance_to(position)) * FACTOR

You will have to adjust the FACTOR constant that is responsible for how fast the body will scale up to meet your requirements.

Hi, can you please explain what do you mean by Origin_location, I have no luck scaling my character.

Dream | 2021-09-26 19:11

The ORIGIN_LOCATION is the variable that contains the location the player is moving away from. The greater the distance from the player to this distance is, the smaller the player will be scaled.

Spyrex | 2021-10-22 13:58