This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello,

I am making a to be multiplayer FPS. My current system is that the game's weapons are children of the player and a signal is required to go from the player to the weapon. Right now I am trying to make a grenade launcher type thing that shoots capsule pills that will latter explode. I have gotten the player to tell the gun to shoot the projectiles, but when it comes to writing code for the projectile itself I am at a loss. I don't know how the rigidbody projectile can efficiently and cleanly tell the shooter the damage it dealt and other information, and how to make it check if it collided with another player so I can tell it to explode and then subtract the health of that player. Signals don't seem to be the solution to this because I would have to link a signal to every player every time a projectile is fired and the amount of players it made to be flexible with creating player and bot instances so me implementing multiplayer will be easier.

I don't know how to make the rigidbody projectiles subtract the health of other player instances it collided with.

in Engine by (52 points)

1 Answer

0 votes
Best answer

try using groups for the projectile-player collision detection.

the way you do this is you add the player instance to a group (this is set in the node tab next to the signals button). you should see a text edit area and a button that says "add".
in the text edit area, type in the name of the group you want the player to be in. something like "players" will work fine.

then, in the projectile collision detection, instead of using signals to check if you are colliding with the player, you should check if the colliding node is part of the "players" group.

something like this:

func _physics_process():
   bodies = get_colliding_bodies()
   for body in bodies:
     if body.is_in_group("players"): #check colliding body is in the "players" group
        body.damage(damage) #whatever u want to do (i.e, damage the player)

this'll make sure that only the players will recieve damage, nd not anything else.

note: the group name used in the collision detection should be the same name you put into the player nodes group name.

by (449 points)
selected by
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 [email protected] with your username.