Ignore first collision?

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

Hello!

I’m making a local multiplayer game where there are an arbitrary number of players (so I can’t know in advance).

Let’s say that one player passes a ball to another as in basketball.

I have the problem that when the ball is created inside the player, as soon as it’s created it collides with its creator (note: it has to be inside the player because it’s not really a basketball game, that’s just for a simple visualization).

I need that the ball ignores the player that creates it in the first place, but not the other players (so they can receive the ball) and not the creator after another player has touch it or some time has passed (in the case that the player shoots the ball up to the sky and the ball returns to him).

All the solutions I’ve seen say to use layers and masks but I can’t because all the players “live” in the same layer (players), so the ball ends up ignoring all the players

How can I do this?

Thank you very much!

Is the ball a KinematicBody2D? Are you using move_and_collide()? If so, the returned KinematicCollision2D object can be used to identify what the ball collided with (access the collider property in KinematicCollision2D and have the ball ignore the player that created it). If you’re using move_and_collide(), the signals of move_and_collide() can be used to identify the colliding body so as to filter out the originating player.

Ertain | 2021-12-13 20:04

:bust_in_silhouette: Reply From: spaceyjase

If it’s just a visualisation, why not turn the collider off for the creator and/or use a different layer or just parent the object? You could also add a add_collision_exception_with(node) (doc) and as soon as another player has it, remove the exception.

:bust_in_silhouette: Reply From: NoyesGames

Off the top of my head, you could emit a signal from on_body_exited() which tells all the active players that the game has “begun” and ignore any collisions from the ball prior to that signal being received?