I need help with an object that can collide with the tile map but is deleted when the player touches it. It is a characterbody2d as of right now. The code below is what I have now.
extends CharacterBody2D
var speed = 5
var random1 = randf_range(-1,1)
var random2 = randf_range(-1,1) @onready var animated_sprite_2d = $AnimatedSprite2D
to check collision from characterbody2d and if it collides with player, then queue free itself:
for i in get_slide_collision_count():
var collision = get_slide_collision(i)
if collision.get_collider():
if collision.get_collider().name=="player":
queue_free()
well it works, but you will need an extra area2d to check if the player enters it or not, this will be useful if you want to have a ranged area larger than the enemy body collision shape
well um, if the collision code works, then no need for this anymore
it also could be just your naming is not 100% precise, you sure the body that entered the area is named “player”?