+1 vote

I'm trying to figure out how to allow the player to interact with certain tiles, preferably with single tiles, unless the other options are a lot easier or something. Unfortunately, I can't find any tutorials that aren't part of some big series whereas they explain literally nothing and do half the project off cam, and I don't exactly want to restart my game from scratch. Pretty much the only thing I need to know is the function I'd have to use to detect an interaction with the left mouse button (on a specific tile), and I can do the rest by myself. Please elaborate as much as possible, because I'm dumb.

Godot version Unedited version of 3.3.4
in Engine by (18 points)

1 Answer

0 votes

From one idiot to another... Not sure if this will work, but I feel it might.

Need to create a scene with Area2d Node with a CollisionShape2D. (You can set it up as a cell if all cells are the same - otherwise change the size of the collision shape when you instance the area(editable children must be selected if you right click on the instance))

Under Tile_ Map attach a script and do

const ClickArea = preload("res://ClickArea")

for tile in get_ used_ cells_ by_ id(index_here):
var click_ area = ClickArea.instance()
click_ area.position = tile
add_ child(click_ area)

You would then need to add the click event in the ClickArea script. AND MAKE SURE THE "PICKABLE" selection is ticked
You could also create a tile set of clickable tiles, in which case you could return all tiles used with get_ used_ cells() which would not need an index

Hoping that helps

by (18 points)
edited by
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.