|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
danny57 |
i want to draw custom shapes use them as platforms in my game.
i tried using a StaticBody2D node for this, and i had no problem getting it to draw the shapes, but i got stuck on setting the collision shape, all the threads i could find suggested using a Polygon2D with the shape i want and adding it using the “add_shape” function,
but i get this error:
Invalid call. Nonexistent function ‘add_shape’ in base ‘StaticBody2D (StaticBody2D.gd)’.
what am i doing wrong? should i use a different base?
thanks a lot, im a newcomer just started today
|
|
|
|
Reply From: |
kidscancode |
add_shape()
is not a function of StaticBody2D.
CollisionObject2D nodes (static/rigid/kinematic) have an api for adding shapes:
but it can be complex to use, as you need to create a shape owner and then add the shape, etc.
It’s much more straightforward if you use CollisionPolygon2D:
Add it as a child of your StaticBody2D and set the polygon
property using the same point array you used for your Polygon2D:
$CollisionPolygon2D.polygon = $Polygon2D.polygon
Bless you mate, may i ask what is the meaning of the dollar signs you typed in the code?
danny57 | 2018-06-05 19:50
The $
in GDScript is a shorthand for get_node()
. So it means the same to write
get_node("CollisionPolygon2D")
as
$CollisionPolygon2D
kidscancode | 2018-06-05 19:55