Attention | Topic was automatically imported from the old Question2Answer platform. | |
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