0 votes

I am working in Godot 3.1 beta. I have a TileMap with collision I am trying to determine if the tile I am standing on has shape_one_way = true.

So far, I have managed to determine the index of the tile I am standing on, but I don't know how to go about using the index to access the tile's properties from code.

if bottomleft_ray.is_colliding() or bottomright_ray.is_colliding():
    var collider
    var collision_point
    if bottomleft_ray.is_colliding():
        collider = bottomleft_ray.get_collider()
        collision_point = bottomleft_ray.get_collision_point()
    elif bottomright_ray.is_colliding():
        collider = bottomright_ray.get_collider()
        collision_point = bottomright_ray.get_collision_point()

    print(collider.name) # prints "TileMap"

    var cell_location = collider.world_to_map(collision_point)
    var cell = collider.get_cell(cell_location.x, cell_location.y)

    # if cell has shape_one_way = true, do stuff...

This works as far as it goes, and cell is the index of the particular tile in the TileMap that my player is standing on (in this case, it's 1).

But how can I go about accessing shape_one_way for this tile to see if it's true?

in Engine by (1,567 points)

1 Answer

+1 vote
Best answer

The tile_set property contains the TileMap's tile data resource, which gives you a TileSet object. At which point you could do:

if collider.tile_set.tile_get_shape_one_way(cell, 0):

Note this assumes there's only one shape on the tile. If your tiles have multiple shapes, you'll have to use tile_get_shapes() and iterate through them.

by (20,899 points)
selected by

Thanks! This also appears to work: collider.tile_set.get(String(cell) + "/shape_one_way")

I suppose, but pure get() calls like that look uglier and reduce readability, in my opinion.

I think you're right! Good call.

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.