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?

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

asked Jul 29, 2017 in Engine by DDNW (12 points)
edited Jul 30, 2017 by DDNW

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.

Thankyou

answered Aug 9, 2017 by gulatihardik10 (24 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),

answered Aug 9, 2017 by eons (7,786 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.