Ice Area2D tilemap

Godot Version

4.4

Question

I have a tilemap with a scene in it of a sprite with an area 2d.
When these tiles are in a line body enterened and body exited happens multiple times. i dont want it to happen multiple times.

(Says hi when body enter and bye when body exit)

its a tilemap from a scene collection

Does the multiple enter/exit cause a problem? What are you trying to solve specifically?

Im trying to make it more slippery for the player entering and exiting messes with the code because it sets a variable.

When true move toward 0 speed/30
When false move toward 0 speed/3

Currently it will sometimes work but then stop working when i enter a new tile

How about instead of setting a boolean true/false variable you use a integer to count how many tiles are overlapping

On enter ice_count += 1, on exit ice_count -= 1, then you can check if ice_count > 0: instead of true/false.


Maybe you can share the rest of the code to be certain? Make sure to paste betwee three ticks for proper formatting

```
func my_code() -> void:
    print("hi")
```

turns into

func my_code() -> void:
    print("hi")

thats a good idea i didnt think of that

That worked perfectly thank you!

You could potentially generate the Area2D nodes at runtime, by coalescing the areas of the tiles that are icy.

You could put edge detection with some hysteresis on the enter/exit, if you want to have multiples:

var on_ice        = false # are we on ice?
var entered_ice   = 0     # refcount
var ice_countdown = 0.0   # cooldown timer

func entering_ice():
    on_ice = true    # Definitely on ice.
    entered_ice += 1 # Up the refcount.

func leaving_ice():
    entered_ice -= 1     # Maybe leaving ice?  Dec refcount.
    ice_countdown = 0.25 # Set a countdown for _process()

func _process(delta: float):
    if entered_ice <= 0 && ice_countdown: # refcount zero + cooldown
        ice_countdown -= delta
        if ice_countdown <= 0.0:
            on_ice = false

With that you should be able to check on_ice for whether the player is currently on ice.

That could potentially glitch depending on the order things update…

i just made it so the area 2ds overlap slightly seems to be no issues

1 Like