diff --git a/Subsurface/Source/Characters/AICharacter.cs b/Subsurface/Source/Characters/AICharacter.cs index c56f4814e..e059b7ab8 100644 --- a/Subsurface/Source/Characters/AICharacter.cs +++ b/Subsurface/Source/Characters/AICharacter.cs @@ -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; } diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index aba1f100d..daaf5d039 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -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; diff --git a/Subsurface/Source/Characters/FishAnimController.cs b/Subsurface/Source/Characters/FishAnimController.cs index e67fb4c0b..c27c42c37 100644 --- a/Subsurface/Source/Characters/FishAnimController.cs +++ b/Subsurface/Source/Characters/FishAnimController.cs @@ -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; diff --git a/Subsurface/Source/Characters/HumanoidAnimController.cs b/Subsurface/Source/Characters/HumanoidAnimController.cs index e77cb263d..8989b719d 100644 --- a/Subsurface/Source/Characters/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/HumanoidAnimController.cs @@ -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(); diff --git a/Subsurface/Source/Characters/Ragdoll.cs b/Subsurface/Source/Characters/Ragdoll.cs index 97287c92b..f1e9bcd7c 100644 --- a/Subsurface/Source/Characters/Ragdoll.cs +++ b/Subsurface/Source/Characters/Ragdoll.cs @@ -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() { diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index d04e4cd2e..f1e4067e6 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -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; diff --git a/Subsurface/Source/Networking/NetworkEvent.cs b/Subsurface/Source/Networking/NetworkEvent.cs index d4c48c1e5..2633d6903 100644 --- a/Subsurface/Source/Networking/NetworkEvent.cs +++ b/Subsurface/Source/Networking/NetworkEvent.cs @@ -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; } diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 12ca20a9d..6e0018820 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ