Reduce the scale of a node while keeping it on ground

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

Hello, I’m new to Godot. I’m trying to make a game where the player is constantly moving on a ground and scaling down (But not exceeding 0.1 in scale) and if you click, the player scales up. The problem is when the player is scaling down/up he doesn’t stick to the ground he just sort of floats because he’s scaling according to his center point. Here is the code I’m using:

Extends Area2D

func _process(delta):

scale -= Vector2 (2, 2) * delta
if scale <= Vector2(0.1, 0.1):
	scale = Vector2(0.1, 0.1)
if Input.is_action_pressed("scale"):
	scale += Vector2 (0.1, 0.1)
:bust_in_silhouette: Reply From: Inces

You just need to simultanously move him down by scale amount of height, and back up.
Or just apply gravity and floor collision so it will happen naturally

:bust_in_silhouette: Reply From: chesse

Hello hommixo,

if your Area2D is the base node of the player, you should have something like

as it is discriped in the Godot documentation.

Here you can move the sprite and the collision shape up by spriteHeight/2. This way your Area2D.position is located in the bottom/center of your sprite and collision shape, and the scalling is happing towards this point.

You can set the position manuelle in die sprite and the collision shape or by script in the _ready function, like

$Sprite.position.y = -1 * ($Sprite.texture.get_height()/2)
$CollisionShape2D.position.y = -1 * ($Sprite.texture.get_height()/2)