Hi everyone,
I’m fairly new in Godot & working on a mechanism and need some advice / insights.
In my Multiplayer game I have two types of players being a Survivor and a Blob.
I need a mechanism where the Blob can temporarily “absorb” a survivor.
This would mean that if the blob gets close enough to the survivor, he starts absorbing, and does damage to the survivor. both the survivor and blob should be temporarily blocked from movement.
Currently I have the following code, but this does not really seem to work. My RPC calls aren’t correctly sent/received for some reason…
... code to check if the monster is close enough to a survivor.
// If a survivor is found within range, request to absorb
if (closestSurvivor != null && !_isAbsorbing)
{
if (!Multiplayer.IsServer())
{
GD.Print("Requesting to absorb survivor: " + closestSurvivor.Name);
RpcId(SERVER_ID, nameof(RequestAbsorbSurvivor), closestSurvivor.GetPath());
}
else
{
AbsorbSurvivor(closestSurvivor, SERVER_ID);
}
}
[Rpc(MultiplayerApi.RpcMode.AnyPeer)]
public void RequestAbsorbSurvivor(NodePath survivorPath)
{
if (!Multiplayer.IsServer())
return;
Survivor survivor = GetNode<Survivor>(survivorPath);
if (survivor != null && !_isAbsorbing)
{
AbsorbSurvivor(survivor, Multiplayer.GetRemoteSenderId());
}
}
public async void AbsorbSurvivor(Survivor targetSurvivor, int clientBlobId)
{
_isAbsorbing = true;
BlockOwnMovementOrRpcToClients(targetSurvivor, clientBlobId, true);
// Wait for the eating duration
await Task.Delay((int)(absorbDuration * 1000));
targetSurvivor.TakeDamage(absorbDamage);
BlockOwnMovementOrRpcToClients(targetSurvivor, clientBlobId, false);
_isAbsorbing = false;
}
private void BlockOwnMovementOrRpcToClients(Survivor survivor, int clientBlobId, bool block)
{
// Immobilize both Blob and Survivor. Survivor.Name is set to the clientId on player spawning
int survivorClientId = int.Parse(survivor.Name);
if (survivorClientId == SERVER_ID)
{
survivor.BlockMovement(block);
RpcId(clientBlobId, nameof(BlockMovement), block);
}
else if (clientBlobId == SERVER_ID)
{
this.BlockMovement(block);
RpcId(survivorClientId, nameof(BlockMovement), block);
}
else
{
RpcId(survivorClientId, nameof(BlockMovement), block);
RpcId(clientBlobId, nameof(BlockMovement), block);
}
}
So basically I’m checking if the blob/survivor is the server, and if it is, block the movement of the player locally and otherwise send out an RPC call to the specific clientId of the blob/player.
For some reason, RPC calls seem to be correctly sent out but are not received on the clients while the clientIDs are correct.
This whole mess made me realise that I might just be doing this mechanic wrong so that’s why I need some input from the professionals themselves
If you see any mistakes in my code, feel free to correct me! I’m here to learn
Don’t worry to ask for more questions if you feel like this is not enough information.
Thanks! <3