CalKyanite
CalKyanite

Reputation: 21

Godot 4 - How can I have a tile in a tilemap with a different clickable area?

I'm trying out game programming in Godot, and working on an isometric 2D game. I'm trying to add ramps and elevation, and have run into a problem. Elevation works, fine, but the clickable area for ramps works strangely. If I translate the mouse coordinates directly to grid coordinates, only the area in the orange diamond in this picture is clickable. This works fine for cubic tiles, but not for ramps.

As such, I'd like to have a different clickable area for the player to select the ramp tiles.

There are a few ideas I have that might work, but I'm not sure how to implement them using godot's system.

  1. I can add a custom check for input within a vicinity of a tile containing a ramp. This is tedious and requires tuning per individual tile. While I'm confident that it would work, it would make design much more tedious, especially as I plan on adding different tilesets which might have a slightly different ramp shape.

  2. I can look for opaque pixels at each layer where the user clicked. This would work, but I'm not sure if a command exists within Godot's tileMap class that would allow for it. The docs weren't helpful, but I admit I could have missed something.

  3. If Godot allows for a certain tile within a tileSet object to have a custom area, that could work as well, but that doesn't seem very much in line with the way that those classes are set up.

I'm also not particularly attached to Godot, so if someone sees this and has a better game engine they'd like to suggest for doing this, I'd listen.

Upvotes: 2

Views: 539

Answers (1)

MeSteve95
MeSteve95

Reputation: 131

One way you could accomplish this is to define a Physics Layer for the TileSet. This allows for you to define which physics layer(s) the TileSet will interact with, as well as allows for defining custom shapes for the Tiles.

As an example, your TileSet resource could look like:

TileSetPhysicsLayers

You could then paint a custom physics hitbox for the ramp Tiles or any other Tiles that have unique shapes.

TilePhysicsLayerPaint

By using this method, your mouse interaction script could then check to determine whether the mouse click hit a Tile within its hitbox, and use that for determining the clickable areas for Tiles. All non-ramp Tiles are also able to use the same hitbox shape, so you only need to define custom shapes for Tiles that need them!

Upvotes: 1

Related Questions