CollisionShape2D - get area

I want to find what the area of my colision shape is so i can add y to another.

extends CollisionShape2D


# Called when the node enters the scene tree for the first time.
func _ready():
	#get colision shape and find what height it is
	var shape = get_shape()
	var height = shape.get_area()
	print(height)

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass

i get info that:
image

while documentation says

can someone please help me, what am i doing wrong

it seems get_shape returns the Shape2D shape property of CollisionShape2D according to the documentation of CollisionShape2D. This shape doesn’t have an area property as you can see in the documentation

Shape2D — Godot Engine (stable) documentation in English

It has a Rect2 rect property you can access via get_rect(). On this rect you can use get_area() to recover the area.
So if you want to get area, you can use var area = shape.get_rect().get_area(). If you want height, you probably want to use var height = shape.get_rect().size.y

ah, my bad. Thank you so much it works :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.