![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | sphixy011 |
hello
i need help
i want to change the size of my collision shape in script
can you help me
![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | sphixy011 |
hello
i need help
i want to change the size of my collision shape in script
can you help me
![]() |
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
I’m not sure if this is down to the Godot version (I’m using 4.2), but using shape.extents = Vector2(x, y)
for a RectangleShape2D gave me weird behavior. Instead I used shape.set_size(Vector2(x, y)
which seems to work as intended.
Does this still work in godot 4.2?