0 votes

Hi all, I want to exactly align an Area2D to a node2D.

The problem is the area 2D has been SCALED, so when I do this:

$Area1.global_position = $node2D1.global_position

It aligns but it's centred in the top left corner of the node2D.

How can I find a way to offset the area2D so the the top left of it exactly aligns to the top left of the node2d?

in Engine by (810 points)

1 Answer

+1 vote

First of all, a Node2D and Area2D both don't have a size. What you perceive as size is either the sprite or the collision shape they have.
They don't align because your collision shape is centered but the child of your other Node2D is not.

I see two ways to center tour area:

1) When you assign the position of the area, add an offset equal to half the size of your area, half the size of the target node2d, or an average of both if their size differ

2) Design your game objects such as their root is centered instead of being top-left

by (27,172 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 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 webmaster@godotengine.org with your username.

Categories