Changing player sprite based on the tile he's standing on

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rouge_bleu

Hello Everyone, I’m wondering how I can change my player sprite based on the tile type he’s standing on.

My goal is to modify the player sprite when he walks in shallow water. He’s feet should be hidden and there should be some animation of water splashing around him.

The thing is I don’t even know where to start…

It sounds quite common, so I guess someone knows how to do that, any ideas?

Thanks in advance !

:bust_in_silhouette: Reply From: Gluon

Have multiple different animations on your character, one for walking normally and one for walking in water. Put an area2d over the water tiles and connect a body entered too the player, then have a line of code which checks if the body entering the area2d is the player as below

func _on_area2d_entered(body):
    if body  == self:

then connect a signal from the area2d for on body exiting area2d and connect it to similar code in the player which plays the normal walking animation.

Thanks that’s a great idea but for my games, the areas of water are huge and pretty irregular, that’s why I think the effect should come from the tilemap instead of manually placing area2D everywhere. Or what happen if I make a area 2D subnode from the ile map, does the area becomes de tilemap ?

rouge_bleu | 2022-12-25 16:28

Yes you can add an area2d to the tilemap scene. You will need to connect the signal through code that way rather than through the godot UI but it would still work.

Gluon | 2022-12-25 16:30