Fixed camera going insane when dropping through hatches

TODO: make the game less rubberbandy
This commit is contained in:
juanjp600
2017-12-12 21:08:37 -03:00
parent b3178c6ab1
commit c4e894cb2e
2 changed files with 20 additions and 4 deletions
@@ -1339,17 +1339,33 @@ namespace Barotrauma
}
}
Hull serverHull = Hull.FindHull(serverPos.Position, character.CurrentHull, false);
Hull clientHull = Hull.FindHull(localPos.Position, serverHull, false);
Vector2 positionError = serverPos.Position - localPos.Position;
float rotationError = serverPos.Rotation - localPos.Rotation;
for (int i = localPosIndex; i < character.MemLocalState.Count; i++)
if (serverHull!=clientHull && ((serverHull==null) || (clientHull==null) || (serverHull.Submarine != clientHull.Submarine)))
{
character.MemLocalState[i].Translate(positionError,rotationError);
//hull subs don't match => just teleport the player to exactly this position to avoid mismatches,
//since this would completely break the camera
positionError = Collider.SimPosition - serverPos.Position;
character.MemLocalState.Clear();
}
else
{
for (int i = localPosIndex; i < character.MemLocalState.Count; i++)
{
Hull pointHull = Hull.FindHull(character.MemLocalState[i].Position, clientHull, false);
if (pointHull != clientHull && ((pointHull == null) || (clientHull == null) || (pointHull.Submarine == clientHull.Submarine))) break;
character.MemLocalState[i].Translate(positionError, rotationError);
}
}
Collider.SetTransform(Collider.SimPosition + positionError, Collider.Rotation + rotationError);
foreach (Limb limb in Limbs)
{
limb.body.SetTransform(limb.body.SimPosition + positionError, limb.body.Rotation + rotationError);
limb.body.SetTransform(limb.body.SimPosition + positionError, limb.body.Rotation);
}
}