How to get the radius/width of Area2D or CollisionShape2D?

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

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:

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?

:bust_in_silhouette: Reply From: kidscancode

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:


Just what I was looking for!

mimimomo | 2018-09-16 22:50

What if the shape is a rectangle?

not-a-robot | 2019-12-12 14:18

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

kidscancode | 2019-12-12 14:21