How to hide a body when it collides with 2d Area ?

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

Hello There :slight_smile:

i have an Area 2D character he must avoid viruses or he will die
and he has to take the pills in order to get bonus ( both rigid bodies 2D )
how i can hide the pills after the player collide with them !!! (the collides happen and the prove is my bonus increases in HUD)

why i can’t call the function which suppose to hide the Pills from the pill script !!!

This is my First Game In GODOT :slight_smile:

below pill script # which i want to hide when the player collide with them

extends RigidBody2D
export(int) var MAX_SPEED
export(int) var MIN_SPEED
var Pill_types=[‘Green’,‘Red’,‘Blue’,‘Yellow’]

func _ready():
$AnimatedSprite.animation=Pill_types[randi()% Pill_types.size()]

func Pill_flee():

func die ():

here is the detect function in player’s script

i put this line before fun _ready ()

var Pill= preload(“res://scene/Pill.tscn”)

func Body_Detect(body):

if body.is_in_group("Enemies"):
if body.is_in_group("Collectible"):
	var pill_child= Pill.instance()
	emit_signal("eat")    # call score update in main
	Pill_child.die()           # call die() func in Pill
:bust_in_silhouette: Reply From: Magso

The easiest way is to use body.get_parent().remove_child(body) or body.queue_free(). You can also toggle the Sprite visibility by checking the body’s children.

for child in body.get_children():
    if child is Sprite:
        child.visible = false

Just edited it from MeshInstance to Sprite but the code’s pretty much the same.

Wow… it Worked :smiley:

Thank you Sooooooo Much Dude :*

you saved me from going Crazy :smiley:

Zylo_X | 2020-04-14 18:47