The problem: I have a weapon that can be turned on and off, and when it's turned on, it loops a sound. The weapon is supposed to retain its state when it is dropped, so if the weapon was turned on, the sound should continue playing. The current logic makes inventory items stop all sounds when they are moved in or out of inventory, so I'm using an auxiliary "sound source" actor to loop the sound. When the weapon is in the owner's inventory, the sound source is attached to the owner, and when the weapon is dropped, the sound source is re-attached to the weapon. Here is a stripped-down testable example of what the code for this actor looks like:
Code: Select all
class SoundSource : Actor
{
Default
{
+NOINTERACTION;
}
override void BeginPlay()
{
Super.BeginPlay();
target = players[0].mo;
A_PlaySound("weapons/sawidle", CHAN_WEAPON, looping: true);
}
override void Tick()
{
if (target)
{
SetOrigin(target.pos, false);
}
else
{
Destroy();
}
}
}
When summoned, this actor attaches itself to the first player and constantly loops the sound "weapons/sawidle". In single player it works perfectly, and it is impossible to tell that the sound isn't coming from the player itself. However, in multiplayer this setup breaks. Depending on whether the player is standing still, moving or turning around, the perceived position of the sound's source is constantly changing: the sound is heard either only in the left or only in the right speaker, and its volume also appears to be non-constant. It's as if the sound source actor cannot catch up with the player's position for some reason (even though the effect of SetOrigin with the second argument set to false should be instantaneous, shouldn't it?).
I thought it could be an issue related to network lag, but I've tested it in a multiplayer setup where two GZDoom instances running on the local machine are connected to each other, and the problem still persists. Maybe I'm missing something in my actor definition or I should also do something else besides calling SetOrigin when repositioning the actor? Though it does look more like a bug to me because the behavior is not consistent between singleplayer and multiplayer modes.