How to prevent the player from leaving the map?

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

I have a player (KinematicBody2D) on a map made with TileMap and want to restrict the player to this space only. I already put a limit on the camera (so the player can’t see spaces around the map). Is there any way to do this?

:bust_in_silhouette: Reply From: tastyshrimp

I believe the most common way to block the player is to add a “wall” around your tile map.
Either as an actual wall tile that blocks the player and is around the entire map, think Zelda where there are trees or mountains covering the entire side of the map.
Or an invisible wall which is basically a StaticObject2D without a sprite that simply does not let the player through, like GTA for example.