Godot Tip 「Tile Collision With Tilemap and a Physics Body」

Posted by SysL, on January 24, 2025. [Link]

This is how you can detect what tiles you are colliding with when using a Physics Body.


Blog Image


extends Node2D

@export var area: Area2D
@export var map: TileMap

func _ready():
area.body_shape_entered.connect(area_entered)

func area_entered(_body_rid: RID, _body: Node2D, _body_shape_index: int, _local_shape_index: int):
map.erase_cell(0,map.get_coords_for_body_rid(_body_rid))


Information from BipBop (Godot Engine Forms, December 13 , 2023)