- Edited
I'm new to working in Godot, and this is something I've been trying to figure out for a bit now. I searched for solutions, but couldn't find anything useful.
To put it simply, I have ground type tiles and water type tiles. I want the character animation to change when the character is standing on water tiles.
I've given the water tiles an "is_water" custom data layer, and then in the Player code, I check whether the player is standing on a water tile, and change the animation based on that. It does work, however there is a slight sprite changing delay when the character steps in and out of water (so the water animation still plays for a couple of frames when the player steps onto the ground, and the ground animation still plays for a bit when the player steps into the water).
My question is whether is possible to somehow get rid of the delay, or maybe do this process in a different way?
The relevant code:
func _physics_process(delta):
var forward_animation : String = "forward_run"
var back_animation : String = "back_run"
var right_animation : String = "right_run"
var left_animation : String = "left_run"
var tilemap = get_tree().get_current_scene().get_node("TileMap")
var tile_data = tilemap.get_cell_tile_data(0, tilemap.local_to_map(global_position))
if (tile_data.get_custom_data("is_water")):
forward_animation = "water_" + forward_animation
back_animation = "water_" + back_animation
right_animation = "water_" + right_animation
left_animation = "water_" + left_animation
run_speed = water_run_speed