0 votes

Hi there! I have a problem that I dont know how to solve. I've created in my game a spawn area in which there are different objects appearing randomly. My problem is that some times the objects appear really close each others and sometimes they overlap too.

I tried to solve it putting a collision shape to the objects that I'm instancing, but I dont know that didn't work (using the apropiate nodes types). I think that maybe using a function like "is_colliding" or something like that I can make that the object moves until it is not colliding with other object, but there are not a function called like that (I tried all the different physics objects).

Also the problem is that when they appear (when they are instancied) using signals it dont detect the collision because it is already inside the shape. (Sorry for my english jaja it is not very well).

Can someone help me? Thanks!

in Engine by (12 points)

Do you use layer and layer mask?

Yes, but all of them have the same layer because they are instancied objects. I mean, they have a different layer that the player has, this way the player donĀ“t collide with them, but the objects have all the same layer and mask because they are the same object but instancied several times :D

1 Answer

0 votes

In the Platformer 2D Demo this is used in player.gd to not collide as soon as projectiles are instanced into the scene:

if Input.is_action_just_pressed("shoot"):
    var bullet = preload("res://bullet.tscn").instance()
    ...
    bullet.add_collision_exception_with(self)

There are other functions for managing collisions in PhysicsBody2D.
If they are RigidBody2D there is a contact_monitor that can be enabled.

If nothing of that helps please sharing your project so we get some more context of your question.

by (911 points)
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.