Improved character movement lag compensation
This commit is contained in:
@@ -120,8 +120,6 @@ namespace Barotrauma
|
||||
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
|
||||
//message.Write(AnimController.RefLimb.LinearVelocity.X);
|
||||
//message.Write(AnimController.RefLimb.LinearVelocity.Y);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -501,16 +501,14 @@ namespace Barotrauma
|
||||
|
||||
float findClosestTimer;
|
||||
|
||||
public void Control(float deltaTime, Camera cam)
|
||||
public Vector2 GetTargetMovement()
|
||||
{
|
||||
if (isDead || AnimController.StunTimer>0.0f) return;
|
||||
|
||||
Vector2 targetMovement = Vector2.Zero;
|
||||
if (IsKeyDown(InputType.Left)) targetMovement.X -= 1.0f;
|
||||
if (IsKeyDown(InputType.Right)) targetMovement.X += 1.0f;
|
||||
if (IsKeyDown(InputType.Up)) targetMovement.Y += 1.0f;
|
||||
if (IsKeyDown(InputType.Down)) targetMovement.Y -= 1.0f;
|
||||
|
||||
if (IsKeyDown(InputType.Up)) targetMovement.Y += 1.0f;
|
||||
if (IsKeyDown(InputType.Down)) targetMovement.Y -= 1.0f;
|
||||
|
||||
//the vertical component is only used for falling through platforms and climbing ladders when not in water,
|
||||
//so the movement can't be normalized or the character would walk slower when pressing down/up
|
||||
if (AnimController.InWater)
|
||||
@@ -525,6 +523,15 @@ namespace Barotrauma
|
||||
targetMovement *= SpeedMultiplier;
|
||||
SpeedMultiplier = 1.0f;
|
||||
|
||||
return targetMovement;
|
||||
}
|
||||
|
||||
public void Control(float deltaTime, Camera cam)
|
||||
{
|
||||
if (isDead || AnimController.StunTimer>0.0f) return;
|
||||
|
||||
Vector2 targetMovement = GetTargetMovement();
|
||||
|
||||
AnimController.TargetMovement = targetMovement;
|
||||
AnimController.IsStanding = true;
|
||||
|
||||
@@ -1439,15 +1446,15 @@ namespace Barotrauma
|
||||
AnimController.IsStanding = true;
|
||||
|
||||
keys[(int)InputType.Use].Held = actionKeyState;
|
||||
keys[(int)InputType.Aim].Held = secondaryKeyState;
|
||||
keys[(int)InputType.Aim].Held = secondaryKeyState;
|
||||
|
||||
if (sendingTime <= LastNetworkUpdate) return;
|
||||
|
||||
keys[(int)InputType.Left].Held = leftKeyState;
|
||||
keys[(int)InputType.Left].Held = leftKeyState;
|
||||
keys[(int)InputType.Right].Held = rightKeyState;
|
||||
|
||||
keys[(int)InputType.Up].Held = upKeyState;
|
||||
keys[(int)InputType.Down].Held = downKeyState;
|
||||
keys[(int)InputType.Up].Held = upKeyState;
|
||||
keys[(int)InputType.Down].Held = downKeyState;
|
||||
|
||||
keys[(int)InputType.Run].Held = runState;
|
||||
|
||||
@@ -1496,7 +1503,7 @@ namespace Barotrauma
|
||||
cursorPosition = Position + new Vector2(1000.0f, 0.0f) * dir;
|
||||
}
|
||||
|
||||
AnimController.RefLimb.body.TargetPosition = pos;
|
||||
AnimController.RefLimb.body.TargetPosition = AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now + message.SenderConnection.RemoteTimeOffset) - sendingTime);
|
||||
|
||||
LastNetworkUpdate = sendingTime;
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace Barotrauma
|
||||
|
||||
void UpdateSineAnim(float deltaTime)
|
||||
{
|
||||
movement = MathUtils.SmoothStep(movement, TargetMovement*swimSpeed, 1.0f);
|
||||
movement = TargetMovement*swimSpeed;
|
||||
if (movement.LengthSquared() < 0.00001f) return;
|
||||
|
||||
if (!inWater) movement.Y = Math.Min(0.0f, movement.Y);
|
||||
@@ -183,7 +183,7 @@ namespace Barotrauma
|
||||
//current * (float)alpha + previous * (1.0f - (float)alpha);
|
||||
|
||||
|
||||
steerForce = (movement * 50.0f - head.LinearVelocity * 30.0f);
|
||||
steerForce = (movement+correctionMovement) * 50.0f - head.LinearVelocity * 30.0f;
|
||||
// force += (headMovement - movement) * Math.Min(head.LinearVelocity.Length()/movement.Length(), 1.0f);
|
||||
|
||||
if (!inWater) steerForce.Y = 0.0f;
|
||||
|
||||
@@ -910,6 +910,17 @@ namespace Barotrauma
|
||||
hand.body.SmoothRotate((ang2 + handAngle * Dir), 100.0f * force);
|
||||
}
|
||||
|
||||
public override Vector2 EstimateCurrPosition(Vector2 prevPosition, float timePassed)
|
||||
{
|
||||
timePassed = MathHelper.Clamp(timePassed, 0.0f, 1.0f);
|
||||
|
||||
Vector2 targetMovement = character.GetTargetMovement();
|
||||
|
||||
Vector2 currPosition = prevPosition + targetMovement * timePassed/1000.0f;
|
||||
|
||||
return currPosition;
|
||||
}
|
||||
|
||||
public override void Flip()
|
||||
{
|
||||
base.Flip();
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Barotrauma
|
||||
|
||||
//a movement vector that overrides targetmovement if trying to steer
|
||||
//a character to the position sent by server in multiplayer mode
|
||||
private Vector2 correctionMovement;
|
||||
protected Vector2 correctionMovement;
|
||||
|
||||
protected float floorY;
|
||||
protected float surfaceY;
|
||||
@@ -692,15 +692,15 @@ namespace Barotrauma
|
||||
{
|
||||
if (inWater)
|
||||
{
|
||||
foreach (Limb limb in Limbs)
|
||||
{
|
||||
//if (limb.body.TargetPosition == Vector2.Zero) continue;
|
||||
//foreach (Limb limb in Limbs)
|
||||
//{
|
||||
// //if (limb.body.TargetPosition == Vector2.Zero) continue;
|
||||
|
||||
//limb.body.SetTransform(limb.SimPosition + newMovement * 0.1f, limb.Rotation);
|
||||
}
|
||||
// limb.body.SetTransform(limb.SimPosition + Vector2.Normalize(diff) * 0.1f, limb.Rotation);
|
||||
//}
|
||||
|
||||
correctionMovement =
|
||||
Vector2.Lerp(targetMovement, Vector2.Normalize(diff) * MathHelper.Clamp(dist * 5.0f, 0.1f, 5.0f), 0.2f);
|
||||
Vector2.Lerp(targetMovement, Vector2.Normalize(diff) * MathHelper.Clamp(dist * 8.0f, 0.1f, 8.0f), 0.2f);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -732,6 +732,11 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Vector2 EstimateCurrPosition(Vector2 prevPosition, float timePassed)
|
||||
{
|
||||
return prevPosition;
|
||||
}
|
||||
|
||||
|
||||
private Vector2 GetFlowForce()
|
||||
{
|
||||
|
||||
@@ -105,10 +105,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect)
|
||||
{
|
||||
|
||||
Vector2 center = new Vector2(rect.Center.X, rect.Center.Y);
|
||||
//lineEnd += new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * Math.Min(width, height) / 2.0f;
|
||||
//GUI.DrawLine(spriteBatch, GuiFrame.Center, lineEnd, Color.Green);
|
||||
|
||||
if (!IsActive) return;
|
||||
|
||||
|
||||
@@ -170,7 +170,9 @@ namespace Barotrauma.Networking
|
||||
Entity e = Entity.FindEntityByID(id);
|
||||
if (e == null)
|
||||
{
|
||||
//DebugConsole.ThrowError("Couldn't find an entity matching the ID ''" + id + "''");
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("Couldn't find an entity matching the ID ''" + id + "''");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user