how to rigidbody collision tilemap

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

A rigidbody hits a tilemap. How do you know what tile was hit so you can set its cell to -1

The position of the rigidbody is not the position of the tile. That has an offset. I could start doing some calculations, size of rigidbody + velocity length etc to know what tile it hit. But that seems not the way to go.

There is a function on the tilemap .get_used_rect() that would be perfect… If only it would give the tile that the rigedbody hits. I would need something like tilemap.get_colllising_rect() so I can set the cell -1.

If using kinematic body then there are more easy solutions for this. Why not with rigidbody?

:bust_in_silhouette: Reply From: Zylann

The approach needed here is to get the contact points, and then get tiles from their positions.
RigidBody2D doesn’t expose them directly with getter functions, however there is the _integrate_forces function which you can override, and its parameter allows you to get all contact points: RigidBody2D — Godot Engine (3.0) documentation in English

Here is an example in Godot 3:
http://zylannprods.fr/dl/godot/RigidBodyContactsTilemap.zip