Problems accessing data from CustomDataLayers on my tilemaplayer

Godot Version

4.5.1.Stable

Question

Hi there! i have a escalator block in my game that moves the player depending on the cell they they are standing on, i have 4 different cells (up down left right) and ive attached custom data to each as a sting stating if they’re left, right etc cell. im still not exactly sure how to corectly grab this data from the cells. i have some code here from a tutorial that i used and its not detecting still and i need some help understanding how to correctly grab specific cell data and then using it :)?

this part of my script is in my player controller script which is attached to my player and the function is refrenced in the physics process.

func tilemap_detecting_handler(delta):
    for i in get_slide_collision_count():
        var collision = get_slide_collision(i)
        var collider := collision.get_collider()
                
                # detects escalator tile
        if collision.get_collider().is_in_group("Escalator"):
            onEscalator = true
                
            if collider is TileMapLayer:
                var layer := collider as TileMapLayer
                var hit_pos := collision.get_position()
                var cell := layer.local_to_map(hit_pos)
                var tile_data := layer.get_cell_tile_data(cell)

                if tile_data:
                    var is_left = tile_data.get_custom_data("Left")

                    if is_left:
                        print("Escalator moving LEFT")
        else: onEscalator = false
1 Like

I think i know what might be happening here.

var is_left = tile_data.get_custom_data("Left")

doesn’t work before you don’t have a Custom Data called “left”. So that code always returns null because it cant find a variable called left.

What you do have is a Custom Data variable called “Direction Facing” (its visible in your screenshot).

What you need to do is retrieve the Variable containing the direction value using

var dir_facing : String = tile_data.get_custom_data("Direction Facing")

then compare its value.

if dir_facing == "left":
print("Escalator moving left");

that should help you with that issue. you might also double check if you player is colliding with the Escalator and you actually detecting it.

omg tysm that works almost perfectly!!!

im just having a problem where it seems the only part of the player that is colliding is the bottom right corner, is there anyway to have the whole bottom of my player detecting the tiles or is that just how godot precesses collisions?