how to change the size of the collision shape in script

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

hello
i need help
i want to change the size of my collision shape in script
can you help me

1 Like
:bust_in_silhouette: Reply From: kidscancode

It depends on what shape you’re using. Each of the Shape2D objects has its own properties. For example, radius for CircleShape2D or extents for RectangleShape2D.

As an example, if you have a CollisionShape2D with a RectangleShape2D as its shape:

$CollisionShape2D.shape.extents = Vector2(x, y)

or a circle shape:

$CollisionShape2D.shape.radius = some_value

I have this exact code for radius and it doesn’t work. Seeing it all over the forum yet it’s straight broken. That sucks. Hopefully an update will fix that.

tool
onready var spawnRadiusShape = $SpawnRadius/CollisionShape2D.shape.radius
export var radius = 100

func _process(delta):
	if Engine.editor_hint:
 		spawnRadiusShape = radius

(SpawnRadius is an Area2D)

PIZZA_ALERT | 2022-09-09 00:30

how about this

onready var range_area_size = $RangeArea/CollisionShape2D.shape.set_radius(radius)
export var radius = 10

Undorobo | 2022-10-22 01:10