Sync character collider rotation, try to make collider face the main limb by instantly flipping it if the angle's too wide, client-side ragdoll correction is more aggressive

This commit is contained in:
juanjp600
2017-12-12 17:58:49 -03:00
parent 7ce93d2e1f
commit 23b220b6af
6 changed files with 41 additions and 22 deletions
@@ -83,9 +83,13 @@ namespace Barotrauma
{
levitatingCollider = false;
Collider.FarseerBody.FixedRotation = false;
Collider.LinearVelocity = (GetLimb(LimbType.Waist).SimPosition - Collider.SimPosition) * 20.0f;
Collider.SmoothRotate(GetLimb(LimbType.Torso).Rotation);
if (Math.Abs(Collider.Rotation-GetLimb(LimbType.Torso).Rotation)>Math.PI*0.6f)
{
Collider.SetTransform(Collider.SimPosition, MathHelper.WrapAngle(Collider.Rotation + (float)Math.PI));
}
Collider.SmoothRotate(GetLimb(LimbType.Torso).Rotation);
Collider.LinearVelocity = (GetLimb(LimbType.Waist).SimPosition - Collider.SimPosition) * 20.0f;
return;
}
@@ -1339,13 +1339,18 @@ namespace Barotrauma
}
}
Vector2 positionError = serverPos.Position - localPos.Position;
Vector2 positionError = serverPos.Position - localPos.Position;
float rotationError = serverPos.Rotation - localPos.Rotation;
for (int i = localPosIndex; i < character.MemLocalState.Count; i++)
{
character.MemLocalState[i].Translate(positionError);
character.MemLocalState[i].Translate(positionError,rotationError);
}
Collider.SetTransform(Collider.SimPosition + positionError, Collider.Rotation);
Collider.SetTransform(Collider.SimPosition + positionError, Collider.Rotation + rotationError);
foreach (Limb limb in Limbs)
{
limb.body.SetTransform(limb.body.SimPosition + positionError, limb.body.Rotation + rotationError);
}
}
if (character.MemLocalState.Count > 120) character.MemLocalState.RemoveRange(0, character.MemLocalState.Count - 120);
@@ -15,18 +15,18 @@ namespace Barotrauma
public readonly AnimController.Animation Animation;
public CharacterStateInfo(Vector2 pos, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, 0, time, dir, interact, animation)
public CharacterStateInfo(Vector2 pos, float rotation, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, rotation, 0, time, dir, interact, animation)
{
}
public CharacterStateInfo(Vector2 pos, UInt16 ID, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, ID, 0.0f, dir, interact, animation)
public CharacterStateInfo(Vector2 pos, float rotation, UInt16 ID, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: this(pos, rotation, ID, 0.0f, dir, interact, animation)
{
}
protected CharacterStateInfo(Vector2 pos, UInt16 ID, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: base(pos, ID, time)
protected CharacterStateInfo(Vector2 pos, float rotation, UInt16 ID, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
: base(pos, rotation, ID, time)
{
Direction = dir;
Interact = interact;
@@ -197,6 +197,7 @@ namespace Barotrauma
{
var posInfo = new CharacterStateInfo(
SimPosition,
AnimController.Collider.Rotation,
LastNetworkUpdateID,
AnimController.TargetDir,
SelectedCharacter == null ? (Entity)selectedConstruction : (Entity)SelectedCharacter,
@@ -467,6 +468,7 @@ namespace Barotrauma
tempBuffer.Write(SimPosition.X);
tempBuffer.Write(SimPosition.Y);
tempBuffer.Write(AnimController.Collider.Rotation);
tempBuffer.WritePadBits();