0 votes

Ive been searching all over the internet for answers, to no avail.

Each player has a "hp" variable that goes down when taking damage.

What im trying to do but cant figure out is,
how can i use a raycast to identify the clientside non-network-master player node, and subtract from their hp variable.

Godot version 3.3
in Engine by (70 points)

1 Answer

+1 vote
Best answer

I think the main sources you're looking for are Raycasting and High level Multiplayer. Basically you just write a normal (singleplayer) raycasting script. There are plenty of tutorials on this.
Then you read into the High level Multiplayer section about "RPC" and "Master Puppet Keywords". The raycast/shooting method should execute only on the puppet and the set_health method should be executed synchronized on the master and all puppets.

by (330 points)
selected by

i found "rpcid(TARGETPEERID,"method"), how do i get this TARGETPEER_ID, from a raycast collision?

existing code:

if colliding:
    var collider = raycast.get_collider()
    if collider.has_method("_take_damage"):
        rpc(collider,"_take_damage")

should something like this work?^^^

This is good advice, as MagnusS said start with a singleplayer when everything works implement RPC calls using the NetworkedMultiplayerENet.

You'll have to research Godot's Multiplayer framework as RPC's are disabled by default.

To get the id you'll have to use either get_tree().get_network_unique_id() or get_tree().get_network_connected_peers()

how would you go about doing get_tree().get_network_unique_id(), in a raycast collision?

var ID = get_tree().get_network_unique_id()

But that line alone would be useless as a network needs to be setup, started, and peers connected as well as RPC keywords set to enable packet transfer

Also that function returns your id on the network so using it standalone would only be sending RPC 's to selfpeer. Have a look at the links provided above as it's a great place to start.

You should save the network id of the player in a variable in the character. Then you can read that variable once your raycast hits a character.

PS: If you liked the answer, please upvote and maybe select it as accepted answer

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.