Up to date
This page is up to date for Godot
If you still find outdated information, please open an issue.
Collision shapes (2D)¶
This guide explains:
The types of collision shapes available in 2D in Godot.
Using an image converted to a polygon as a collision shape.
Performance considerations regarding 2D collisions.
Godot provides many kinds of collision shapes, with different performance and accuracy tradeoffs.
You can define the shape of a PhysicsBody2D by adding one or more CollisionShape2Ds or CollisionPolygon2Ds as child nodes. Note that you must add a Shape2D resource to collision shape nodes in the Inspector dock.
When you add multiple collision shapes to a single PhysicsBody2D, you don't have to worry about them overlapping. They won't "collide" with each other.
Primitive collision shapes¶
Godot provides the following primitive collision shape types:
SeparationRayShape2D (designed for characters)
WorldBoundaryShape2D (infinite plane)
You can represent the collision of most smaller objects using one or more primitive shapes. However, for more complex objects, such as a large ship or a whole level, you may need convex or concave shapes instead. More on that below.
We recommend favoring primitive shapes for dynamic objects such as RigidBodies and KinematicBodies as their behavior is the most reliable. They often provide better performance as well.
Convex collision shapes¶
Godot currently doesn't offer a built-in way to create 2D convex collision shapes. This section is mainly here for reference purposes.
Convex collision shapes are a compromise between primitive collision shapes and concave collision shapes. They can represent shapes of any complexity, but with an important caveat. As their name implies, an individual shape can only represent a convex shape. For instance, a pyramid is convex, but a hollow box is concave. To define a concave object with a single collision shape, you need to use a concave collision shape.
Depending on the object's complexity, you may get better performance by using multiple convex shapes instead of a concave collision shape. Godot lets you use convex decomposition to generate convex shapes that roughly match a hollow object. Note this performance advantage no longer applies after a certain amount of convex shapes. For large and complex objects such as a whole level, we recommend using concave shapes instead.
Concave or trimesh collision shapes¶
Concave collision shapes, also called trimesh collision shapes, can take any form, from a few triangles to thousands of triangles. Concave shapes are the slowest option but are also the most accurate in Godot. You can only use concave shapes within StaticBodies. They will not work with KinematicBodies or RigidBodies unless the RigidBody's mode is Static.
Even though concave shapes offer the most accurate collision, contact reporting can be less precise than primitive shapes.
When not using TileMaps for level design, concave shapes are the best approach for a level's collision.
You can configure the CollisionPolygon2D node's build mode in the inspector. If it is set to Solids (the default), collisions will include the polygon and its contained area. If it is set to Segments, collisions will only include the polygon edges.
You can generate a concave collision shape from the editor by selecting a Sprite2D an