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)