How to set the shape of a RigidBody2D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By equestor
:warning: Old Version Published before Godot 3 was released.

Hi everyone

I am new to using Godot Engine but see it’s potential because of it’s structure and license. I have a rather basic question, how does one set the shape, or edge, and size of a RigidShape2D, be it a rectangle, circle, triangle and a more complex shape? Is there a tutorial on this?

Looking forward to your replies.

:bust_in_silhouette: Reply From: bruteforce

Add a CollisionShape2D as child node of the RigidBody2D, then set its “Shape” property (circleshape/rectangleshape… etc.).
enter image description here

If you want a custom polygon, you can use CollisionPolygon2D (instead of CollisionShape2D). In this case you have to add the coordinates manually one by one (pencil icon on the toolbar).
enter image description here

:bust_in_silhouette: Reply From: eons

Official tutorial:
http://docs.godotengine.org/en/stable/tutorials/2d/physics_introduction.html

More (not focused on shapes but almost all use them):


TL;DR

Via scene editor, you can set the shape adding a CollisionShape2D or CollisionPolygon2D as a child of the body(one child per shape), then set the shape type, most types have visual ways to modify the shapes.
These nodes are editor helpers, not the actual shapes (which are resources, not nodes).

Via code, use set_shape or add_shape with the Shape resource you want.