Made item syncing look slightly less erratic on client's side
Still kinda glitchy, we might need a more elaborate approach later
This commit is contained in:
@@ -2106,26 +2106,38 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime)
|
public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime)
|
||||||
{
|
{
|
||||||
|
Vector2 newPosition = new Vector2(
|
||||||
body.TargetPosition = new Vector2(
|
|
||||||
msg.ReadFloat(),
|
msg.ReadFloat(),
|
||||||
msg.ReadFloat());
|
msg.ReadFloat());
|
||||||
|
|
||||||
body.FarseerBody.Rotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7);
|
float newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7);
|
||||||
|
|
||||||
body.FarseerBody.Awake = msg.ReadBoolean();
|
body.FarseerBody.Awake = msg.ReadBoolean();
|
||||||
|
|
||||||
|
Vector2 newVelocity = Vector2.Zero;
|
||||||
|
|
||||||
|
//TODO: this code should take previous positions and velocities into account,
|
||||||
|
//rather than use the current values for the comparisons.
|
||||||
|
|
||||||
if (body.FarseerBody.Awake)
|
if (body.FarseerBody.Awake)
|
||||||
{
|
{
|
||||||
body.LinearVelocity = new Vector2(
|
newVelocity = new Vector2(
|
||||||
msg.ReadRangedSingle(-32.0f, 32.0f, 12),
|
msg.ReadRangedSingle(-32.0f, 32.0f, 12),
|
||||||
msg.ReadRangedSingle(-32.0f, 32.0f, 12));
|
msg.ReadRangedSingle(-32.0f, 32.0f, 12));
|
||||||
|
if ((newVelocity-body.LinearVelocity).Length()>8.0f) body.LinearVelocity = newVelocity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
body.FarseerBody.Enabled = false;
|
body.FarseerBody.Enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (body.TargetPosition==null || (newPosition - (Vector2)body.TargetPosition).Length() > body.LinearVelocity.Length() * 3.0f)
|
||||||
|
{
|
||||||
|
body.TargetPosition = newPosition;
|
||||||
|
|
||||||
|
body.FarseerBody.Rotation = newRotation;
|
||||||
|
}
|
||||||
|
|
||||||
DebugConsole.NewMessage("Received item pos, t: "+sendingTime+ " ("+Name+")", Color.LightGreen);
|
DebugConsole.NewMessage("Received item pos, t: "+sendingTime+ " ("+Name+")", Color.LightGreen);
|
||||||
|
|
||||||
/* //already interpolating with more up-to-date data -> ignore
|
/* //already interpolating with more up-to-date data -> ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user