From edafd73dddd3f1e944c4fe2797b125b0ecc27c45 Mon Sep 17 00:00:00 2001 From: Eman Date: Tue, 10 Sep 2024 02:08:32 +0200 Subject: [PATCH] Hand Move Offset enhancements Walk/Run/Crouch animations have a new boolean parameter: "ApplyHandMoveOffsetWhenStationary", set to false by default When set to true, the hands of the character will move into the position defined by "HandMoveOffset" even when it is standing still. Additionally, the horizontal value of the Hand Move Offset parameter no longer changes sign when the character moves backwards. --- .../Animation/HumanoidAnimController.cs | 52 +++++++++++-------- .../Params/Animation/HumanoidAnimations.cs | 3 ++ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/Animation/HumanoidAnimController.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/Animation/HumanoidAnimController.cs index 14c49042d0..16bf16fcda 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/Animation/HumanoidAnimController.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/Animation/HumanoidAnimController.cs @@ -721,6 +721,7 @@ void UpdateStanding() } Vector2 waistPos = waist != null ? waist.SimPosition : torso.SimPosition; + int currentDirectionSign = character.IsFlipped ? -1 : 1; if (movingHorizontally) { @@ -776,29 +777,6 @@ void UpdateStanding() currentGroundedParams.LegBendTorque, currentGroundedParams.FootTorque, currentGroundedParams.FootAngleInRadians); } } - - //calculate the positions of hands - handPos = torso.SimPosition; - handPos.X = -walkPosX * currentGroundedParams.HandMoveAmount.X; - - float lowerY = currentGroundedParams.HandClampY; - - handPos.Y = lowerY + (float)(Math.Abs(Math.Sin(WalkPos - Math.PI * 1.5f) * currentGroundedParams.HandMoveAmount.Y)); - - Vector2 posAddition = new Vector2(Math.Sign(movement.X) * HandMoveOffset.X, HandMoveOffset.Y); - - if (rightHand != null && !rightHand.Disabled) - { - HandIK(rightHand, - torso.SimPosition + posAddition + new Vector2(-handPos.X, (Math.Sign(walkPosX) == Math.Sign(Dir)) ? handPos.Y : lowerY), - currentGroundedParams.ArmMoveStrength, currentGroundedParams.HandMoveStrength); - } - if (leftHand != null && !leftHand.Disabled) - { - HandIK(leftHand, - torso.SimPosition + posAddition + new Vector2(handPos.X, (Math.Sign(walkPosX) == Math.Sign(-Dir)) ? handPos.Y : lowerY), - currentGroundedParams.ArmMoveStrength, currentGroundedParams.HandMoveStrength); - } } else { @@ -845,7 +823,10 @@ void UpdateStanding() FootIK(foot, footPos, legBendTorque, currentGroundedParams.FootTorque, currentGroundedParams.FootAngleInRadians); } } + } + if(!movingHorizontally && !currentGroundedParams.ApplyHandMoveOffsetWhenStationary) + { for (int i = 0; i < 2; i++) { var hand = i == 0 ? rightHand : leftHand; @@ -880,6 +861,31 @@ void UpdateStanding() } } } + else + { + //calculate the positions of hands + handPos = torso.SimPosition; + handPos.X = -walkPosX * currentGroundedParams.HandMoveAmount.X; + + float lowerY = currentGroundedParams.HandClampY; + + handPos.Y = lowerY + (float)(Math.Abs(Math.Sin(WalkPos - Math.PI * 1.5f) * currentGroundedParams.HandMoveAmount.Y)); + + Vector2 posAddition = new Vector2(currentDirectionSign * HandMoveOffset.X, HandMoveOffset.Y); + + if (rightHand != null && !rightHand.Disabled) + { + HandIK(rightHand, + torso.SimPosition + posAddition + new Vector2(-handPos.X, (currentDirectionSign == Math.Sign(Dir)) ? handPos.Y : lowerY), + currentGroundedParams.ArmMoveStrength, currentGroundedParams.HandMoveStrength); + } + if (leftHand != null && !leftHand.Disabled) + { + HandIK(leftHand, + torso.SimPosition + posAddition + new Vector2(handPos.X, (currentDirectionSign == Math.Sign(-Dir)) ? handPos.Y : lowerY), + currentGroundedParams.ArmMoveStrength, currentGroundedParams.HandMoveStrength); + } + } } void UpdateStandingSimple() diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/Params/Animation/HumanoidAnimations.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/Params/Animation/HumanoidAnimations.cs index 3b99941276..7df16efc6b 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/Params/Animation/HumanoidAnimations.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/Params/Animation/HumanoidAnimations.cs @@ -165,6 +165,9 @@ public float FootAngle [Serialize("-0.15, 0.0", IsPropertySaveable.Yes, description: "Added to the calculated hand positions, e.g. a value of {-1.0, 0.0f} would make the character \"drag\" their hands one unit behind them."), Editable(DecimalCount = 2)] public Vector2 HandMoveOffset { get; set; } + [Serialize(false, IsPropertySaveable.Yes, description: "Should the Hand Move Offset values affect the hands even when stationary?"), Editable] + public bool ApplyHandMoveOffsetWhenStationary { get; set; } + [Serialize(-1.0f, IsPropertySaveable.Yes, description: "The position of the hands is clamped below this (relative to the position of the character's torso)."), Editable(DecimalCount = 2)] public float HandClampY { get; set; }