I have a tile in my set named 'ice'. Is it possible to test collision between that particular tile and the player? If so, how?

in Engine

Can you be more specific? Is it topdown game - so Player is on "ice" tile or platformer - pleyer is on top/above a "ice" tile? Is Player KinematicBody2D?

Platformer using KinematicBody2D. Apologies.

I think that you can't use RayCast2D to get specific tile, you will get specific object but I don't think that you can determine what tile index is that TileMapxxxxx object (someone correct me if i'm wrong). The only way I can think of is to check if Player is on the floor with is_on_floor() function. And you will need do add Position2D as a child of Player - one or two pixels below Player feet. Then you need to check if Position2D is inside tile of a "ice" name. Convert Position2D position from pixels to TileMap space: Pos2DTileSpace = Vector2( int (Position2D.x/CellSizeOfTileMap), int( Position2D.y/CellSizeOfTileMap) ), or use TileMap function world_to_map. Then check if Pos2DTileSpace have same index as your "ice" tile with get_cellv function of TileMap (you should preload TileMap in Player script with onready var myMap = get_node("MyTileMap") ). If Player is on the floor and tile index is equal "ice" tile then Player is on ice.

by (244 points)
edited

is_on_floor is a Godot 3 function. I'm on 2.1.5.

Use RayCast2D from Player feet down some pixels instead of is on the floor, or better check for collision normal - if collision normal is pointig up you are on the floor. Then check with Position2D as I suggest it (or just use some Vector2 variable in Player script and set its value below Players feet 2-4 pixels and covert it in tilespace and check for index of tile that position is in).

I got it to work just using the world_to_map function. No raycast needed.

var tpos = tiles.world_to_map(plyr_obj.get_global_pos())
var itile = tiles.get_cellv(Vector2(tpos.x, tpos.y + 1))
print(itile)

This returns the tile ID. I can use this to toggle the ice flag.