0 votes

I'm working on a level generator node. This node places RigidBody2D's within a predefined area. I don't want them to overlap so they should be deleted as soon as they collide. If they are not deleted, they will inform their parent node that they have been placed so that the desired number of them will be generated. If I was using the old Godot this solution would have worked:

func _ready():
if is_colliding():
    queue_free()
else:
    get_parent().placed += 1

What is the equivalent of this in Godot 3? I don't have time to call the moveandslide function as it should be done instant and only once. Maybe there is an alternative way to detect overlapping?

Godot version 3.2.2
in Engine by (35 points)

Have you tried using the signals which are a part of theRigidBody2D class? Signals such as body_entered() and body_shape_entered()?

2 Answers

0 votes

I think this is the direct way to do it. But if you want to avoid seeing the sprites clipping when they just spawn, you simply hide sprites when spawning them and show sprites after the is_colliding() method.

by (341 points)

But is_colliding is not present in Godot 3.

0 votes

Set contact_monitor to true and iterate through get_colliding_bodies() to check for incompatible collisions.

by (1,307 points)

I don't think there is an equivalent for KinematicBody2D's. I need the same process on them too.

Kinematic bodies have move_and_collide() which you can use to get information about possible collisions.

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 Frequently asked questions and 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 [email protected] with your username.