0 votes

I have world made with Tileset (some of tiles have static body and CollisionShape2D).
In game scene there is some tilemap in different collision layers.
I want to detect if there is any tiles with Staticbody in the near of player

First I used just Area2D, with getoverlappingbodies() but it didn' t detected anything.
Then i added CollisionShape as child, and it started detecting player. But in the script before calling the function I change the collision mask to different then that in which the Player is. And why it isn't detecting the Tilemap neither the one that is in the same layer as player, nor the one that is in the layer Area should detect.

Can you please explain to me where have i made mistake?

There are 2 Tilemaps: one is in Layer 0 and detects Layer 0, second is in Layer 1 and detects Layer 1. There is also a Player (borh Layer and detection 0) and his child Area2D

the script look so:



(target world = 1, curent world = 0)

and there are 2 efects: Area2D has a child - CollisionShape2D - detects only Player (Rigidbody)
Area2D dosn't have children - detects nothing

in Engine by (12 points)
edited by

Could you provide more info on the current state of the layers?

done, any ideas?

2 Answers

0 votes

Hi ddnw

This for groups are made for. First of all add all static bodies in a group (call it by any name) that u want to and then use haspoint method for this. Use player.haspoint(ur group).
You can also use dot product for this. Check out math tutorial in godot documentation.
Hope this will help u....and if not comment ur problem in more detail.


by (22 points)
0 votes

The tilemap is a single structure, so, using an area you will get only the Tilemap.

The area mask is where it looks for layers, so mask must be on the same bit the Tilemap is.

But you are going to detect just the overlapping Tilemap, not the individual regions with solid tiles.

If you want specific tiles, a set of raycasts should be better, then you will have to figure the tile is hitting according to the ray characteristics (the hit point moved a bit in ray direction and translated to tilemap coordinates),

by (7,894 points)
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.