Collision Detection with a Pre-Rendered Background

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


I’m trying to have my Player stop moving when their CollisionShape hits a predefined boundary in a map.

Here’s a very basic idea of what this map boundary could look like
. Basically, I want to keep the Player within the white area. The issue I’m having with this is that the geometry of the CollisionShape for this area would be complicated and hollow in different places.

Is there some way that I can achieve this just through the color properties of the image, or by making the white area transparent and preventing the Player CollisionBox with hitting the black part of the image? If not, what would be the best way to implement this?


:bust_in_silhouette: Reply From: Bisdante

You can try attaching a CollisionPolygon2D to StaticBody2D nodes, as it allows drawing complex shapes for collisions manually.