The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+6 votes

Is there a way to reference the radius or width of Area2D, CollisionShape2D or CollisionPolygon2D in Godot 3?

I am making a skill-based RPG. I currently check skill range with an circular Area2D/CollisionShape2D attached to the sprite. If the sprite of the target character overlaps with the Area2D, then the character can cast the skill on them. Here's the range bubbles around the sprites:

Pic: Range Bubbles around Sprites

Next, I want enemies to move to be just in range of the player character. In other words, I want to enemies to move to the position of the player character minus the radius of the character's Area2D. Is there any way to get that information from the Area2D?

in Engine by (27 points)

1 Answer

+10 votes

This information is contained in the shape property of the CollisionShape2D, which is accessed via shape. In your case, since the shapes are CircleShape2D, they will have a radius property. So, to put it all together:

player.get_node("Area2d/CollisionShape2D").shape.radius
by (22,191 points)

Just what I was looking for!

What if the shape is a rectangle?

In that case, shape will return a RectangleShape2D and the size is contained in the extents property.

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.