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:
@@ -138,11 +138,12 @@ namespace Barotrauma
|
|||||||
msg.ReadFloat(),
|
msg.ReadFloat(),
|
||||||
msg.ReadFloat());
|
msg.ReadFloat());
|
||||||
|
|
||||||
|
float rotation = msg.ReadFloat();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
if (GameMain.NetworkMember.Character == this && AllowInput)
|
if (GameMain.NetworkMember.Character == this && AllowInput)
|
||||||
{
|
{
|
||||||
var posInfo = new CharacterStateInfo(pos, networkUpdateID, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation);
|
var posInfo = new CharacterStateInfo(pos, rotation, networkUpdateID, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation);
|
||||||
while (index < memState.Count && NetIdUtils.IdMoreRecent(posInfo.ID, memState[index].ID))
|
while (index < memState.Count && NetIdUtils.IdMoreRecent(posInfo.ID, memState[index].ID))
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
@@ -150,7 +151,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var posInfo = new CharacterStateInfo(pos, sendingTime, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation);
|
var posInfo = new CharacterStateInfo(pos, rotation, sendingTime, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation);
|
||||||
while (index < memState.Count && posInfo.Timestamp > memState[index].Timestamp)
|
while (index < memState.Count && posInfo.Timestamp > memState[index].Timestamp)
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
|
|||||||
@@ -84,8 +84,12 @@ namespace Barotrauma
|
|||||||
levitatingCollider = false;
|
levitatingCollider = false;
|
||||||
Collider.FarseerBody.FixedRotation = false;
|
Collider.FarseerBody.FixedRotation = false;
|
||||||
|
|
||||||
Collider.LinearVelocity = (GetLimb(LimbType.Waist).SimPosition - Collider.SimPosition) * 20.0f;
|
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.SmoothRotate(GetLimb(LimbType.Torso).Rotation);
|
||||||
|
Collider.LinearVelocity = (GetLimb(LimbType.Waist).SimPosition - Collider.SimPosition) * 20.0f;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1340,12 +1340,17 @@ 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++)
|
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);
|
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 readonly AnimController.Animation Animation;
|
||||||
|
|
||||||
public CharacterStateInfo(Vector2 pos, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
|
public CharacterStateInfo(Vector2 pos, float rotation, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
|
||||||
: this(pos, 0, time, dir, interact, animation)
|
: this(pos, rotation, 0, time, dir, interact, animation)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharacterStateInfo(Vector2 pos, UInt16 ID, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
|
public CharacterStateInfo(Vector2 pos, float rotation, UInt16 ID, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
|
||||||
: this(pos, ID, 0.0f, dir, interact, animation)
|
: 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)
|
protected CharacterStateInfo(Vector2 pos, float rotation, UInt16 ID, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None)
|
||||||
: base(pos, ID, time)
|
: base(pos, rotation, ID, time)
|
||||||
{
|
{
|
||||||
Direction = dir;
|
Direction = dir;
|
||||||
Interact = interact;
|
Interact = interact;
|
||||||
@@ -197,6 +197,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
var posInfo = new CharacterStateInfo(
|
var posInfo = new CharacterStateInfo(
|
||||||
SimPosition,
|
SimPosition,
|
||||||
|
AnimController.Collider.Rotation,
|
||||||
LastNetworkUpdateID,
|
LastNetworkUpdateID,
|
||||||
AnimController.TargetDir,
|
AnimController.TargetDir,
|
||||||
SelectedCharacter == null ? (Entity)selectedConstruction : (Entity)SelectedCharacter,
|
SelectedCharacter == null ? (Entity)selectedConstruction : (Entity)SelectedCharacter,
|
||||||
@@ -467,6 +468,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
tempBuffer.Write(SimPosition.X);
|
tempBuffer.Write(SimPosition.X);
|
||||||
tempBuffer.Write(SimPosition.Y);
|
tempBuffer.Write(SimPosition.Y);
|
||||||
|
tempBuffer.Write(AnimController.Collider.Rotation);
|
||||||
|
|
||||||
tempBuffer.WritePadBits();
|
tempBuffer.WritePadBits();
|
||||||
|
|
||||||
|
|||||||
@@ -1258,7 +1258,7 @@ namespace Barotrauma
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
subBody.MemPos.Insert(index, new PosInfo(newTargetPosition, sendingTime));
|
subBody.MemPos.Insert(index, new PosInfo(newTargetPosition, 0.0f, sendingTime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,22 +16,29 @@ namespace Barotrauma
|
|||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float Rotation
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
public readonly float Timestamp;
|
public readonly float Timestamp;
|
||||||
public readonly UInt16 ID;
|
public readonly UInt16 ID;
|
||||||
|
|
||||||
public PosInfo(Vector2 pos, float time)
|
public PosInfo(Vector2 pos, float rotation, float time)
|
||||||
: this(pos, 0, time)
|
: this(pos, rotation, 0, time)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public PosInfo(Vector2 pos, UInt16 ID)
|
public PosInfo(Vector2 pos, float rotation, UInt16 ID)
|
||||||
: this(pos, ID, 0.0f)
|
: this(pos, rotation, ID, 0.0f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PosInfo(Vector2 pos, UInt16 ID, float time)
|
protected PosInfo(Vector2 pos, float rotation, UInt16 ID, float time)
|
||||||
{
|
{
|
||||||
Position = pos;
|
Position = pos;
|
||||||
|
Rotation = rotation;
|
||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
|
|
||||||
Timestamp = time;
|
Timestamp = time;
|
||||||
@@ -52,9 +59,9 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Translate(Vector2 amount)
|
public void Translate(Vector2 posAmount,float rotationAmount)
|
||||||
{
|
{
|
||||||
Position += amount;
|
Position += posAmount; Rotation += rotationAmount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user