+1 vote

I have instanced objects that erase themself with timer.

when they are insade a areanode(placed on enemies) code will do something, but while stil insade the areanode, instanced objects erase themselfs.

So area's inside get empty, when its get empty, i wanna do something else, but area body_entered function not update itself like process function, so i cant get the return value, or dont know how?

area:

func _body_entered(body):
    body = instance_piece
    if body == instance_piece:
        follow_triger = 1
    if area is empty: ### ---> need to do this.
        follow_triger = 0

proces:
func physicsprocess(delta):

    if follow_triger == 1:
        print ("do someting if instanced body entered")
    if follow_triger == 0:
        print ("stop what you are doing if area is empty")

its allways return the follow_triger 1 value.

in Engine by (93 points)

1 Answer

+1 vote
Best answer

getoverlappingbodies() returns all physics nodes in the area.

To replicate unity's OnTriggerStay function

if get_overlapping_bodies().size() > 0:
    for body in get_overlapping_bodies():
        #Do stuff with all bodies in area
by (3,225 points)
selected by

thanks, it works. well, for objects i was using spatials so insteed get_overlapping_bodies, i did use get_overlapping_areas after i did add the area nodes to spatials.

if follow_triger == 1:
    look_at(player.global_transform.origin,Vector3.UP)
if follow_triger == 0:
    print ("object not found")



if area_node.get_overlapping_areas().size() > 1:
        print ("more then 1")
        follow_triger = 1
else:
    follow_triger = 0
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.