Problem with detecting if there is any bodies in Area2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DDNW
:warning: Old Version Published before Godot 3 was released.

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 get_overlapping_bodies() 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?

EDIT:
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:

get_node("/root/Game").get_children()[0].get_node("Area2D").set_collision_mask_bit(Worlds[curent_world],true)
get_node("/root/Game").get_children()[0].get_node("Area2D").set_collision_mask_bit(Worlds[target_world],false)

[0].get_node("Area2D").get_overlapping_bodies())

(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

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

Dr_TwiSteD | 2017-07-30 07:01

done, any ideas?

DDNW | 2017-08-03 13:17

:bust_in_silhouette: Reply From: gulatihardik10

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 has_point method for this. Use player.has_point(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.

Thankyou

:bust_in_silhouette: Reply From: eons

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),