0 votes

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!

in Engine by (63 points)

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.

2 Answers

0 votes

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.

by (418 points)
0 votes

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

by (19 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 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 webmaster@godotengine.org with your username.