Tilemap get_cell_tile_data not grabbing tile data, based in player script

Godot Version

Godot 4.2

Question

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)
	
	move_and_slide()
	
	var tile_data = $"../TileMap".get_cell_tile_data(0, position, true)
	print(tile_data)
	
	if tile_data:
		friction = tile_data.get_custom_data("floor")
	else:
		friction = 100
	
	print(friction)
	

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