Signal _on_body_enter() not working in tileset?

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

Hey there.

I am trying since hours to get this fixed.
I have a tileset, the sprites in the set have Area2D and CollisionPolygon2D child nodes.
My player is a KinematicBody2D node.

One of my tiles is supposed to be “water” and i want to react to the player standing in (colliding with) a water-tile.

So for testing, i am just trying to print() a message in the console, if my player node collides with a water tile.

I set up a signal body_entered (because my player is a kinematicBody) on the Area2D of the water tile.

extends Area2D

func _on_Area2D_body_entered(body):
print("body entered tile")

I tried to attach the signal to my player, to the sprite of the tile, everything i could think of, with no luck at all.

The signals work on single sprites with Area2D child nodes, though.

Does this mean, i cannot detect such collisions in a tileset at all? This would pretty much mess up my level-design-approach.

Any ideas?

Indeed it doesnt work. I tried to replicate that. But the strange thing is that even if i add Area2D node of a tile (in tileset scene) to a group, main script cant find the node.
btw kinematicBody doesnt have body/area_entered signals i think it is only for physics (collide with static bodies or other kinematic bodies)

luckyNyaNya | 2018-07-22 15:05

So, bottom line is that i would have to instanciate single “water”-tiles? And maybe alot of them, depending on the level design.
I wonder how this impacts performance compared to using a tileset…

himynameis | 2018-07-22 19:27

as a workaround u can convert player position to tilemap position with:

var tile_index = tilemap.world_to_map(player.position)

returns tile index as Vector2
then you can test if a tile at this index is a water type:

if tilemap.get_cellv(tile_index) == 0:

change 0 to type of water
get_cell returns an int

luckyNyaNya | 2018-07-22 21:05

i noticed one more thing :smiley:
if u open a tileset.tres where i had sprite->area2D->CollisionShape, the shape is empty:

1/shapes = [  ]

when i change area2D to StaticBody2D this looks like:

1/shapes = [ {
"autotile_coord": Vector2( 0, 0 ),
"one_way": false,
"shape": SubResource( 1 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 32, 32 )
} ]

and with 2nd vesion collision works (although not the way you wanted)

luckyNyaNya | 2018-07-22 21:39