0 votes

Say you have two enemies coming at you from the right on a 2D platformer. With the collision mask on, the first will engage properly but the second will get hung up walking behind the first enemy. With the collision mask off, they will simply overlap and occupy the exact same space. Using something like the distance_to function, what is a good method to prevent this "bunching" behavior? I would like to turn off the collision mask as well, making their separation purely logic driven. Is it possible to "queue" enemies in such a way that the following might be possible? -

1st enemy: approaches and attacks.
2nd enemy: approaches and attacks from the opposite side.
3rd enemy: approaches and gets behind the 1st enemy (idle).
4th enemy: approaches and gets behind the 2nd enemy (idle).
etc.
etc.

Can someone give me some pseudo code for what that might look like? I've tried simple RayCast2D detection, but the results are always buggy and not what is expected.

in Engine by (74 points)

1 Answer

0 votes

You could put another collision shape on a separate layer that only marks the collision between two enemies. Using that way the player still has the collision with enemies as expected and you are free to choose a shape where they collide and overlap in the way you want.

by (36 points)

Bah, I've tried making it collider based, but it's never satisfactory. I've come to the conclusion that I'll need to write an entire system to make this work properly, complete with independent variables stored on each enemy and the player... with all actors communicating with each other. Whiteboard time.

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.