0 votes

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)
in Engine by (20 points)

2 Answers

0 votes
Best answer

Hello hommixo,

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

enter image description here

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)
by (130 points)
selected by
0 votes

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

by (7,925 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.