body_enter/body_exit not working with tileset

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

I am working on a platformer, i’m currently trying to make a little blob guy follow you around, by ducking under platforms, and re apearing at your position, snapped to a tileset. However, if you land on the edge of a platform, his position gets rounded, and he apears off the edge. What I am trying to do is make it so he only pops up if he is colliding with the tileset. However, the body entered and exit signals only run once, and I can’t get it to work. Any ideas? `var collide = false
var targetY = 0
var targetX = 0
var squat = false
signal squat_anim
onready var player = $“…/KinematicBody2D”

func _physics_process(delta):
if position.distance_to(player.position) > 300 and !squat:
emit_signal(“squat_anim”)
if collide and !squat:
$Sprite.frame = move_toward($Sprite.frame, 0, 100 * delta)
else:
$Sprite.frame = move_toward($Sprite.frame, 8, 100 * delta)

func _on_demon_squat_anim():
squat = true
while $Sprite.frame != 8:
yield(get_tree(), “idle_frame”)
yield(player, “is_on_floor”)
position = player.position.snapped(Vector2(64, 0))
squat = false

func _on_demon_body_entered(body):
print(“enter”)
collide = true

func _on_demon_body_exited(body):
print(“exit”)
collide = false`

:bust_in_silhouette: Reply From: Inces

I worked a lot with tilemaps and I would make a function to recognize if given global position is connected to certain tile of tileset, like a platform. If I understand your code correctly You could just apply this function around this line :

position = player.position.snapped(Vector2(64, 0))

To check if this snapped position translated with world_to_map() is in fact platform or above platform with get_cell(), before you teleport your blob.