Tilemap get_cell_tile_data not grabbing tile data, based in player script

Godot Version

Godot 4.2


So my question is that I have a tilemap with get_cell_tile_data, and I want it to receive a custom data of the specific cell that my player is standing on. I will give my script here:

extends CharacterBody2D

@export var speed : int = 150
@export var friction = 5

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
	if Input.get_action_strength("move_up"):
		velocity.y = -speed
		velocity.x = velocity.x/2
	elif Input.get_action_strength("move_down"):
		velocity.y = speed
		velocity.x = velocity.x/2
	elif Input.get_action_strength("move_left"):
		velocity.x = -speed
		velocity.y = velocity.y/2
	elif Input.get_action_strength("move_right"):
		velocity.x = speed
		velocity.y = velocity.y/2
	elif velocity != Vector2.ZERO:
		velocity = velocity.move_toward(Vector2.ZERO, friction)
	var tile_data = $"../TileMap".get_cell_tile_data(0, position, true)
	if tile_data:
		friction = tile_data.get_custom_data("floor")
		friction = 100

You need to convert your characters position to grid coordinates before passing them to get cell tile data.

var tile_data = $“…/TileMap”.get_cell_tile_data(0, local_to_map(position), true)

but local_to_map is not a method in a character body 2D… is there another way to do it?

its a method of tilemap

alright thank you, I might be able to use that