0 votes

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 .getusedrect() that would be perfect... If only it would give the tile that the rigedbody hits. I would need something like tilemap.getcolllisingrect() so I can set the cell -1.

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

in Engine by (75 points)

1 Answer

+1 vote
Best answer

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: http://docs.godotengine.org/en/3.0/classes/class_rigidbody2d.html#class-rigidbody2d-integrate-forces

Here is an example in Godot 3:

by (27,902 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.