#Requested Assistance with Custom Tile Data Detection (Top Down 2D Project)
49 messages · Page 1 of 1 (latest)
Requested Assistance with Custom Tile Data Detection (Top Down 2D Project)
this is how I am handling my movement
and I have this custom data property for each tile
so do you need the custom data of the tile the player is on?
heres also like a video to clear it up
yeah
just like being able to read the number in the code or something if that makes any sense
do you have a reference to the tile map in the player script?
hm not yet i havent looked into that yet, how would you refrence to something thats not a child?
the best way is to have an autoload that gets the references and then the scripts and access that. do you know how to make an autoload?
if you don't. Project > Project Settings > Autoload
so your tile map, or maybe the world node, would have a script on it that gives the autoload the reference to itself like:
func _ready():
references_autoload.tile_map = self
```then the player would get that reference like:
```swift
func _ready():
set_deferred("tile_map", references_autoload.tile_map)
oh ok got it (sorry for the delay i was looking into what exactly an autoload did and it makes sense to me now)
ok so now i have my refrence
now you need the map coords of the tile. TileMap has a local_to_map method so you just need to get the player's position local to the tile map. like this:
#this in on this player
func _process(delta):
var player_tile = tile_map.local_to_map(tile_map.to_local(position))
then you can get the cell's tile data with tile_map.get_cell_tile_data(0, player_tile)
(I'm assuming the ground tiles are on layer 0)
then call get_custom_data on the result of the get_cell_tile_data with the name of the custom data layer you want
it will return the value
alr alr, ill try this
so i keep getting this error, tried to debug it myself but failed
and the "set_deferred" method needs a string input as you did here does that mean i have to define a value with that same name or am i using the wrong node type for the player?
so Invalid get index means that you tried to get a variable that doesn't exist. what did you call the tile map reference in world.gd?
yes, you need a variable with the same name
the same thing, i was seeing if having the underscore changed anything so i changed it for both
the underscore is just for casing style to make it easier to read. you may just have a typo
hmm, so ive tried a few things at this point, autoloading it from a script attatched to the tileset, copy and pasting every name in every intance its refrenced. yet still nada
this is all that i have on it
well it looks like you're trying to get tile_map from world.gd instead of from tilemap_autoload
hm so i do have to set the refrence to the autoload in a script attatched to the Tilemap and use self?
what you have there is fine. the error will be coming from somewhere else. what does it look like in the player script?
and for good measure, the autoload aswell
the actual code of the autoload. it's just a script
oh well i put the autoload code in the world script i might have done this wrong then hang on
it just needs a variable to hold the tile map as it's being transferred
ohhhh ok yeah now I get it, now I don't get that error I'll try to implement the rest of the system
fingers crossed I get the rest first try 💀
ok ok hopefully this is the final error but theres something up with the "to local" method
try replacing the tile_maps with tilemap_autoload.tile_map
that's saying the reference to tile_map is null. it's nota problem with to_local necessarily
OOOOH
Yes this is doing something
thank you so much
ill mess around a bit after a break from this and if it works without issue than ill close
good luck!
