Ignore mouse rotation requests when the player is switching controlled entity
rotation += 2 * Math.PI;
RaisePredictiveEvent(new RequestMouseRotatorRotationEvent
{
- Rotation = rotation
+ Rotation = rotation,
+ User = GetNetEntity(player)
});
return;
RaisePredictiveEvent(new RequestMouseRotatorRotationEvent
{
- Rotation = angle
+ Rotation = angle,
+ User = GetNetEntity(player)
});
}
}
public sealed class RequestMouseRotatorRotationEvent : EntityEventArgs
{
public Angle Rotation;
+ public NetEntity? User;
}
private void OnRequestRotation(RequestMouseRotatorRotationEvent msg, EntitySessionEventArgs args)
{
+ // Ignore the request if the requested entity is not the user's attached entity.
+ // This can happen when a player switches controlled entities while rotating.
+ if (args.SenderSession.AttachedEntity != GetEntity(msg.User))
+ return;
+
if (args.SenderSession.AttachedEntity is not { } ent
|| !TryComp<MouseRotatorComponent>(ent, out var rotator))
{