From 49d4108eebc8a36b96be976e9ff7505e35ad8809 Mon Sep 17 00:00:00 2001
From: Regalis
Date: Wed, 28 Dec 2016 19:56:52 +0200
Subject: [PATCH] Fixed character colliders sinking/floating away when using a
railgun controller underwater
---
Subsurface/Content/Items/Button/button.xml | 2 +-
Subsurface/Content/Items/Weapons/railgun.xml | 3 +-
.../Animation/HumanoidAnimController.cs | 6 +--
.../Items/Components/Machines/Controller.cs | 49 ++++++++++++-------
4 files changed, 37 insertions(+), 23 deletions(-)
diff --git a/Subsurface/Content/Items/Button/button.xml b/Subsurface/Content/Items/Button/button.xml
index 87a5401bd..35954a92c 100644
--- a/Subsurface/Content/Items/Button/button.xml
+++ b/Subsurface/Content/Items/Button/button.xml
@@ -15,7 +15,7 @@
-
+
diff --git a/Subsurface/Content/Items/Weapons/railgun.xml b/Subsurface/Content/Items/Weapons/railgun.xml
index 39ada59ce..2a6ee0ab8 100644
--- a/Subsurface/Content/Items/Weapons/railgun.xml
+++ b/Subsurface/Content/Items/Weapons/railgun.xml
@@ -34,8 +34,9 @@
-
+
+
diff --git a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs
index aa4155906..0a413ba52 100644
--- a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs
+++ b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs
@@ -173,12 +173,10 @@ namespace Barotrauma
levitatingCollider = false;
UpdateClimbing();
break;
- case Animation.UsingConstruction:
- UpdateStanding();
- break;
case Animation.CPR:
UpdateCPR(deltaTime);
break;
+ case Animation.UsingConstruction:
default:
if (character.SelectedCharacter != null) DragCharacter(character.SelectedCharacter);
@@ -567,7 +565,7 @@ namespace Barotrauma
rotation = MathHelper.ToDegrees(rotation);
if (rotation < 0.0f) rotation += 360;
- if (!character.IsRemotePlayer && !aiming)
+ if (!character.IsRemotePlayer && !aiming && Anim != Animation.UsingConstruction)
{
if (rotation > 20 && rotation < 170)
TargetDir = Direction.Left;
diff --git a/Subsurface/Source/Items/Components/Machines/Controller.cs b/Subsurface/Source/Items/Components/Machines/Controller.cs
index ae10f6b79..65a7530b0 100644
--- a/Subsurface/Source/Items/Components/Machines/Controller.cs
+++ b/Subsurface/Source/Items/Components/Machines/Controller.cs
@@ -26,15 +26,15 @@ namespace Barotrauma.Items.Components
private Direction dir;
- //the x-position where the user walks to when using the controller
- private float userPos;
+ //the position where the user walks to when using the controller
+ //(relative to the position of the item)
+ private Vector2 userPos;
private Camera cam;
private Character character;
- [HasDefaultValue(0.0f, false)]
- public float UserPos
+ public Vector2 UserPos
{
get { return userPos; }
set { userPos = value; }
@@ -45,13 +45,16 @@ namespace Barotrauma.Items.Components
{
limbPositions = new List();
- dir = (Direction)Enum.Parse(typeof(Direction), ToolBox.GetAttributeString(element, "direction", "None"), true);
+ userPos = ToolBox.GetAttributeVector2(element, "UserPos", Vector2.Zero);
+ Enum.TryParse(ToolBox.GetAttributeString(element, "direction", "None"), out dir);
+
foreach (XElement el in element.Elements())
{
if (el.Name != "limbposition") continue;
LimbPos lp = new LimbPos();
+
try
{
lp.limbType = (LimbType)Enum.Parse(typeof(LimbType), el.Attribute("limb").Value, true);
@@ -90,23 +93,34 @@ namespace Barotrauma.Items.Components
character.AnimController.Anim = AnimController.Animation.UsingConstruction;
- if (userPos != 0.0f)
+ if (userPos != Vector2.Zero)
{
float torsoX = character.Position.X;
- Vector2 diff = new Vector2(item.Rect.X + UserPos - torsoX, 0.0f);
+ Vector2 diff = (item.WorldPosition + userPos) - character.WorldPosition;
- if (diff!= Vector2.Zero && diff.Length() > 10.0f)
+ if (character.AnimController.InWater)
{
- //character.AnimController.Anim = AnimController.Animation.None;
-
- character.AnimController.TargetMovement = new Vector2(Math.Sign(diff.X), 0.0f);
- character.AnimController.TargetDir = (Math.Sign(diff.X) == 1) ? Direction.Right : Direction.Left;
- return;
+ if (diff.Length() > 30.0f)
+ {
+ character.AnimController.TargetMovement = Vector2.Clamp(diff*0.01f, -Vector2.One, Vector2.One);
+ character.AnimController.TargetDir = diff.X > 0.0f ? Direction.Right : Direction.Left;
+ }
+ else
+ {
+ character.AnimController.TargetMovement = Vector2.Zero;
+ }
}
else
{
- character.AnimController.TargetMovement = Vector2.Zero;
+ diff.Y = 0.0f;
+ if (diff != Vector2.Zero && diff.Length() > 10.0f)
+ {
+ character.AnimController.TargetMovement = Vector2.Normalize(diff);
+ character.AnimController.TargetDir = diff.X > 0.0f ? Direction.Right : Direction.Left;
+ return;
+ }
+ character.AnimController.TargetMovement = Vector2.Zero;
}
}
@@ -115,6 +129,7 @@ namespace Barotrauma.Items.Components
if (limbPositions.Count == 0) return;
character.AnimController.Anim = AnimController.Animation.UsingConstruction;
+
character.AnimController.ResetPullJoints();
if (dir != 0) character.AnimController.TargetDir = dir;
@@ -256,10 +271,10 @@ namespace Barotrauma.Items.Components
dir = dir == Direction.Left ? Direction.Right : Direction.Left;
}
- if (userPos != 0.0f)
+ if (userPos.X != 0.0f)
{
- float diff = (item.Rect.X + UserPos) - item.Rect.Center.X;
- userPos = item.Rect.Center.X - diff - item.Rect.X;
+ float diff = (item.Rect.X + UserPos.X) - item.Rect.Center.X;
+ userPos.X = item.Rect.Center.X - diff - item.Rect.X;
}
for (int i = 0; i < limbPositions.Count; i++)