+1 vote

I am wondering if I can write a custom script for each "block" of my tileset so my character can react differently to each block.

And if I cannot do this, how can I write the custom properties of the blocks?

Godot version 3.4.2 stable
in Engine by (13 points)

2 Answers

0 votes

If it is character that is supposed to react differently depending on neighbouring blocks - than he is the one that should be scripted for this. Easiest option is to make him child of TileMap and detect what are surrounding tiles each move, using TileMaps methods ( getcell, worldto_map ). Finally, when block is detected make one MATCH statement and code chosen behavior under every detected tilemap cell, like in this pseudocode :

var pm = world_to_map(Player_position)
 for tile in [pm + vec2(1,0),pm + vec2(0,1),pm + vec2(-1,0 .... and so on :
        match get_cell(tile) :
               0 :
                      Player.defense += 10
               1:
                      Player.health -= 25

and so on, numbers are indexes of your blocks in tilemap

by (5,557 points)
0 votes

Another option is to use the tilemap to plan out the level design, and then on runtime, replace all the tiles with objects with their own scripts.

by (7,769 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.