+1 vote

hi,so I am using Godot'd GDscript my NPC is a area2d I connected a signal called onbody_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..

in Engine by (22 points)

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

func _on_BodyEntered(body): if body.name == "Water": //And here you can put the stuff you want the NPC to do

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

3 Answers

0 votes

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

by (16 points)
0 votes

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)
by (29 points)
0 votes

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

https://docs.godotengine.org/en/stable/tutorials/physics/physics_introduction.html#collision-layers-and-masks

by (98 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.