How can i use area2d for detecting water tileset?

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

hi,so I am using Godot’d GDscript my NPC is a area2d I connected a signal called _on_body_entered() from NPC but idk how to use specefic tileset to be detected by area2d?
my project is to make an NPC which wander around and when thirst >20 then it will detect water Tileset and go near it…

I didn’t understand your question at all, but if you want to detect water from a tileset you can do this:

  1. Create a Tileset with the water sprites

  2. Use the NPC Area2D to detect the water

if body.name == "Water":
//And here you can put the stuff you want the NPC to do```
[wrap=footnote]Repertix | 2020-12-07 06:34[/wrap]

thanks, one last question how will the NPC know the direction and speed by which it will move towards the tile

prince | 2020-12-08 16:46

:bust_in_silhouette: Reply From: scrub2219

my area2d doesnt even detect kinematic bodys, and the onbody entered signal isnt for tile sets im pretty sure

:bust_in_silhouette: Reply From: milddeva

Try this:

func _on_Player_body_entered(body):
    if body is TileMap:
	    var tile_pos = body.world_to_map(position)
	    var tile_id = body.get_cellv(tile_pos)
:bust_in_silhouette: Reply From: LuizTM

Hi, :slight_smile:
One more alternatives, that I believe that you can use is manage the layer and mask to configure this collisions.