Humanoid animations work better on uneven floors (e.g. "fake stairs" made from wall pieces).
If the floor in front of the character is higher than where the character is standing, the character slows down and lifts its feet more. The position of the feet is also clamped below the waist, preventing the character from doing a backwards somersault when running over "fake stairs".
This commit is contained in:
@@ -237,7 +237,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
Limb leftLeg = GetLimb(LimbType.LeftLeg);
|
Limb leftLeg = GetLimb(LimbType.LeftLeg);
|
||||||
Limb rightLeg = GetLimb(LimbType.RightLeg);
|
Limb rightLeg = GetLimb(LimbType.RightLeg);
|
||||||
|
|
||||||
float getUpSpeed = 0.3f;
|
float getUpSpeed = 0.3f;
|
||||||
float walkCycleSpeed = movement.X * walkAnimSpeed;
|
float walkCycleSpeed = movement.X * walkAnimSpeed;
|
||||||
if (stairs != null)
|
if (stairs != null)
|
||||||
@@ -322,8 +322,11 @@ namespace Barotrauma
|
|||||||
torso.pullJoint.Enabled = true;
|
torso.pullJoint.Enabled = true;
|
||||||
head.pullJoint.Enabled = true;
|
head.pullJoint.Enabled = true;
|
||||||
waist.pullJoint.Enabled = true;
|
waist.pullJoint.Enabled = true;
|
||||||
|
|
||||||
|
float floorPos = GetFloorY(colliderPos + new Vector2(Math.Sign(movement.X) * 0.5f, 1.0f));
|
||||||
|
bool onSlope = floorPos > GetColliderBottom().Y + 0.05f;
|
||||||
|
|
||||||
if (stairs != null)
|
if (stairs != null || onSlope)
|
||||||
{
|
{
|
||||||
torso.pullJoint.WorldAnchorB = new Vector2(
|
torso.pullJoint.WorldAnchorB = new Vector2(
|
||||||
MathHelper.SmoothStep(torso.SimPosition.X, footMid + movement.X * 0.25f, getUpSpeed * 0.8f),
|
MathHelper.SmoothStep(torso.SimPosition.X, footMid + movement.X * 0.25f, getUpSpeed * 0.8f),
|
||||||
@@ -369,20 +372,23 @@ namespace Barotrauma
|
|||||||
//progress the walking animation
|
//progress the walking animation
|
||||||
walkPos -= (walkCycleSpeed / runningModifier) * 0.8f;
|
walkPos -= (walkCycleSpeed / runningModifier) * 0.8f;
|
||||||
|
|
||||||
MoveLimb(leftFoot,
|
for (int i = -1; i < 2; i += 2)
|
||||||
colliderPos + new Vector2(
|
{
|
||||||
stepSize.X,
|
Limb foot = i == -1 ? leftFoot : rightFoot;
|
||||||
(stepSize.Y > 0.0f) ? stepSize.Y : -0.15f),
|
Limb leg = i == -1 ? leftLeg : rightLeg;
|
||||||
15.0f, true);
|
|
||||||
|
|
||||||
MoveLimb(rightFoot,
|
Vector2 footPos = stepSize * -i;
|
||||||
colliderPos + new Vector2(
|
if (stepSize.Y > 0.0f) stepSize.Y = -0.15f;
|
||||||
-stepSize.X,
|
|
||||||
(-stepSize.Y > 0.0f) ? -stepSize.Y : -0.15f),
|
|
||||||
15.0f, true);
|
|
||||||
|
|
||||||
leftFoot.body.SmoothRotate(leftLeg.body.Rotation + MathHelper.PiOver2 * Dir * 1.6f, 20.0f * runningModifier);
|
if (onSlope && stairs == null)
|
||||||
rightFoot.body.SmoothRotate(rightLeg.body.Rotation + MathHelper.PiOver2 * Dir * 1.6f, 20.0f * runningModifier);
|
{
|
||||||
|
footPos.Y *= 2.0f;
|
||||||
|
}
|
||||||
|
footPos.Y = Math.Min(waist.SimPosition.Y - colliderPos.Y - 0.4f, footPos.Y);
|
||||||
|
|
||||||
|
MoveLimb(foot, footPos + colliderPos, 15.0f, true);
|
||||||
|
foot.body.SmoothRotate(leg.body.Rotation + MathHelper.PiOver2 * Dir * 1.6f, 20.0f * runningModifier);
|
||||||
|
}
|
||||||
|
|
||||||
if (runningModifier > 1.0f)
|
if (runningModifier > 1.0f)
|
||||||
{
|
{
|
||||||
@@ -453,7 +459,11 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
footPos = new Vector2(GetCenterOfMass().X + stepSize.X * i * 0.2f, colliderPos.Y - 0.1f);
|
footPos = new Vector2(GetCenterOfMass().X + stepSize.X * i * 0.2f, colliderPos.Y - 0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stairs == null)
|
||||||
|
{
|
||||||
|
footPos.Y = Math.Max(Math.Min(floorPos, footPos.Y + 0.5f), footPos.Y);
|
||||||
|
}
|
||||||
|
|
||||||
var foot = i == -1 ? rightFoot : leftFoot;
|
var foot = i == -1 ? rightFoot : leftFoot;
|
||||||
|
|
||||||
|
|||||||
@@ -1096,7 +1096,12 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
PhysicsBody refBody = refLimb == null ? Collider : refLimb.body;
|
PhysicsBody refBody = refLimb == null ? Collider : refLimb.body;
|
||||||
|
|
||||||
Vector2 rayStart = refBody.SimPosition;
|
return GetFloorY(refBody.SimPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected float GetFloorY(Vector2 simPosition)
|
||||||
|
{
|
||||||
|
Vector2 rayStart = simPosition;
|
||||||
Vector2 rayEnd = rayStart - new Vector2(0.0f, TorsoPosition);
|
Vector2 rayEnd = rayStart - new Vector2(0.0f, TorsoPosition);
|
||||||
|
|
||||||
var lowestLimb = FindLowestLimb();
|
var lowestLimb = FindLowestLimb();
|
||||||
@@ -1125,7 +1130,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
return closestFraction;
|
return closestFraction;
|
||||||
}
|
}
|
||||||
, rayStart, rayEnd);
|
, rayStart, rayEnd);
|
||||||
|
|
||||||
|
|
||||||
@@ -1137,7 +1142,6 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
return rayStart.Y + (rayEnd.Y - rayStart.Y) * closestFraction;
|
return rayStart.Y + (rayEnd.Y - rayStart.Y) * closestFraction;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(Vector2 simPosition, bool lerp = false)
|
public void SetPosition(Vector2 simPosition, bool lerp = false)
|
||||||
|
|||||||
Reference in New Issue
Block a user