From c5ce1be6c2a9cd23c22907d4e25cff2940ff921f Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 12 Jun 2017 19:27:52 +0300 Subject: [PATCH] Running speed can be adjusted from the character configs, added a parameter for the "running speed" in water (characters now swim faster when holding shift). TODO: make AI-controlled monsters run/swim faster in specific situations (fleeing, attacking, etc). --- Barotrauma/Content/Characters/Human/human.xml | 4 ++-- .../Content/Characters/Human/humanhusk.xml | 4 ++-- Barotrauma/Content/Characters/Husk/husk.xml | 4 ++-- .../Characters/Animation/AnimController.cs | 21 ++++++++++++++++--- .../Animation/HumanoidAnimController.cs | 5 ++--- Barotrauma/Source/Characters/Character.cs | 6 ++---- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Barotrauma/Content/Characters/Human/human.xml b/Barotrauma/Content/Characters/Human/human.xml index b0f000efd..0f2e5d1ed 100644 --- a/Barotrauma/Content/Characters/Human/human.xml +++ b/Barotrauma/Content/Characters/Human/human.xml @@ -9,8 +9,8 @@ movementlerp="0.4" legtorque="15.0" thightorque="-5.0" - walkspeed="1.5" - swimspeed="2.0" + walkspeed="1.5" swimspeed="2.0" + runspeedmultiplier="3.0" swimspeedmultiplier="1.5" colliderheightfromfloor="55" impacttolerance="7.5"> diff --git a/Barotrauma/Content/Characters/Human/humanhusk.xml b/Barotrauma/Content/Characters/Human/humanhusk.xml index 52f0e389e..303981949 100644 --- a/Barotrauma/Content/Characters/Human/humanhusk.xml +++ b/Barotrauma/Content/Characters/Human/humanhusk.xml @@ -9,8 +9,8 @@ movementlerp="0.4" legtorque="15.0" thightorque="-5.0" - walkspeed="1.5" - swimspeed="2.5" + walkspeed="1.5" swimspeed="2.5" + runspeedmultiplier="2.0" swimspeedmultiplier="1.5" impacttolerance="7.5"> diff --git a/Barotrauma/Content/Characters/Husk/husk.xml b/Barotrauma/Content/Characters/Husk/husk.xml index 9ea4a67d2..537f7d584 100644 --- a/Barotrauma/Content/Characters/Husk/husk.xml +++ b/Barotrauma/Content/Characters/Husk/husk.xml @@ -11,8 +11,8 @@ movementlerp="0.4" legtorque="15.0" thightorque="-5.0" - walkspeed="1.2" - swimspeed="2.5"> + walkspeed="1.2" swimspeed="2.5" + runspeedmultiplier="2.0" swimspeedmultiplier="1.5"> diff --git a/Barotrauma/Source/Characters/Animation/AnimController.cs b/Barotrauma/Source/Characters/Animation/AnimController.cs index 8eb710cd9..a27aa384f 100644 --- a/Barotrauma/Source/Characters/Animation/AnimController.cs +++ b/Barotrauma/Source/Characters/Animation/AnimController.cs @@ -12,13 +12,25 @@ namespace Barotrauma protected Character character; - protected float walkSpeed, swimSpeed; - + protected float walkSpeed, swimSpeed; + protected float walkPos; protected readonly Vector2 stepSize; protected readonly float legTorque; - + + public float RunSpeedMultiplier + { + get; + private set; + } + + public float SwimSpeedMultiplier + { + get; + private set; + } + public AnimController(Character character, XElement element) : base(character, element) { @@ -30,6 +42,9 @@ namespace Barotrauma walkSpeed = ToolBox.GetAttributeFloat(element, "walkspeed", 1.0f); swimSpeed = ToolBox.GetAttributeFloat(element, "swimspeed", 1.0f); + RunSpeedMultiplier = ToolBox.GetAttributeFloat(element, "runspeedmultiplier", 2f); + SwimSpeedMultiplier = ToolBox.GetAttributeFloat(element, "swimspeedmultiplier", 1.5f); + legTorque = ToolBox.GetAttributeFloat(element, "legtorque", 0.0f); } diff --git a/Barotrauma/Source/Characters/Animation/HumanoidAnimController.cs b/Barotrauma/Source/Characters/Animation/HumanoidAnimController.cs index 74de33026..d359ce3a0 100644 --- a/Barotrauma/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Barotrauma/Source/Characters/Animation/HumanoidAnimController.cs @@ -571,7 +571,6 @@ namespace Barotrauma } float targetSpeed = TargetMovement.Length(); - if (targetSpeed > 0.0f) TargetMovement /= targetSpeed; if (targetSpeed > 0.1f) { @@ -633,7 +632,7 @@ namespace Barotrauma Collider.LinearVelocity = Vector2.Lerp(Collider.LinearVelocity, movement * swimSpeed, movementLerp); } - walkPos += movement.Length() * 0.15f; + walkPos += movement.Length() * 0.2f; footPos = Collider.SimPosition - new Vector2((float)Math.Sin(-Collider.Rotation), (float)Math.Cos(-Collider.Rotation)) * 0.4f; for (int i = -1; i<2; i+=2) @@ -691,7 +690,7 @@ namespace Barotrauma handPos += head.LinearVelocity * 0.1f; - float handCyclePos = walkPos / 3.0f * -Dir; + float handCyclePos = walkPos / 2.0f * -Dir; float handPosX = (float)Math.Cos(handCyclePos) * 0.4f; float handPosY = (float)Math.Sin(handCyclePos) * 1.0f; handPosY = MathHelper.Clamp(handPosY, -0.8f, 0.8f); diff --git a/Barotrauma/Source/Characters/Character.cs b/Barotrauma/Source/Characters/Character.cs index 0e133f1fa..5f6230d2d 100644 --- a/Barotrauma/Source/Characters/Character.cs +++ b/Barotrauma/Source/Characters/Character.cs @@ -785,16 +785,14 @@ namespace Barotrauma if (IsKeyDown(InputType.Run)) { //can't run if - // - not a humanoid // - dragging someone // - crouching // - moving backwards - if (AnimController is HumanoidAnimController && - selectedCharacter == null && + if (selectedCharacter == null && !((HumanoidAnimController)AnimController).Crouching && Math.Sign(targetMovement.X) != -Math.Sign(AnimController.Dir)) { - targetMovement *= 3.0f; + targetMovement *= AnimController.InWater ? AnimController.SwimSpeedMultiplier : AnimController.RunSpeedMultiplier; } }