Collider isn't moved to the position of the main limb when frozen, limb collisions are temporarily disabled if the ragdoll is too far from the collider, some cleanup
This commit is contained in:
@@ -15,8 +15,6 @@ namespace Barotrauma
|
||||
private float waveAmplitude;
|
||||
private float waveLength;
|
||||
|
||||
private Limb mainLimb;
|
||||
|
||||
private bool rotateTowardsMovement;
|
||||
|
||||
private bool mirror, flip;
|
||||
@@ -45,19 +43,16 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
rotateTowardsMovement = ToolBox.GetAttributeBool(element, "rotatetowardsmovement", true);
|
||||
|
||||
Limb torso = GetLimb(LimbType.Torso);
|
||||
Limb head = GetLimb(LimbType.Head);
|
||||
|
||||
mainLimb = torso == null ? head : torso;
|
||||
}
|
||||
|
||||
public override void UpdateAnim(float deltaTime)
|
||||
{
|
||||
if (character.IsDead || Frozen || character.IsUnconscious || stunTimer > 0.0f)
|
||||
if (Frozen) return;
|
||||
|
||||
if (character.IsDead || character.IsUnconscious || stunTimer > 0.0f)
|
||||
{
|
||||
collider.PhysEnabled = false;
|
||||
collider.SetTransform(mainLimb.SimPosition, 0.0f);
|
||||
collider.SetTransform(MainLimb.SimPosition, 0.0f);
|
||||
|
||||
if (stunTimer > 0.0f)
|
||||
{
|
||||
@@ -169,32 +164,24 @@ namespace Barotrauma
|
||||
Limb torso = GetLimb(LimbType.Torso);
|
||||
Limb head = GetLimb(LimbType.Head);
|
||||
|
||||
mainLimb.pullJoint.Enabled = true;
|
||||
mainLimb.pullJoint.WorldAnchorB = collider.SimPosition;
|
||||
MainLimb.pullJoint.Enabled = true;
|
||||
MainLimb.pullJoint.WorldAnchorB = collider.SimPosition;
|
||||
|
||||
if (movement.LengthSquared() < 0.00001f) return;
|
||||
|
||||
float movementAngle = MathUtils.VectorToAngle(movement) - MathHelper.PiOver2;
|
||||
|
||||
|
||||
|
||||
if (rotateTowardsMovement)
|
||||
{
|
||||
collider.SmoothRotate(movementAngle, 25.0f);
|
||||
mainLimb.body.SmoothRotate(movementAngle, 25.0f);
|
||||
MainLimb.body.SmoothRotate(movementAngle, 25.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
collider.SmoothRotate(HeadAngle * Dir, 25.0f);
|
||||
mainLimb.body.SmoothRotate(HeadAngle * Dir, 25.0f);
|
||||
MainLimb.body.SmoothRotate(HeadAngle * Dir, 25.0f);
|
||||
}
|
||||
|
||||
//float angle = (rotateTowardsMovement) ?
|
||||
// mainLimb.body.Rotation + MathUtils.GetShortestAngle(mainLimb.body.Rotation, movementAngle) :
|
||||
// HeadAngle * Dir;
|
||||
|
||||
//collider.SmoothRotate(angle, 25.0f);
|
||||
//mainLimb.body.SmoothRotate(angle, 25.0f);
|
||||
|
||||
Limb tail = GetLimb(LimbType.Tail);
|
||||
if (tail != null && waveAmplitude > 0.0f)
|
||||
{
|
||||
@@ -211,11 +198,11 @@ namespace Barotrauma
|
||||
Vector2 pullPos = Limbs[i].pullJoint == null ? Limbs[i].SimPosition : Limbs[i].pullJoint.WorldAnchorA;
|
||||
Limbs[i].body.ApplyForce(movement * Limbs[i].SteerForce * Limbs[i].Mass, pullPos);
|
||||
|
||||
if (Limbs[i] == mainLimb) continue;
|
||||
if (Limbs[i] == MainLimb) continue;
|
||||
|
||||
float dist = (mainLimb.SimPosition - Limbs[i].SimPosition).Length();
|
||||
float dist = (MainLimb.SimPosition - Limbs[i].SimPosition).Length();
|
||||
|
||||
Vector2 limbPos = mainLimb.SimPosition - Vector2.Normalize(movement) * dist;
|
||||
Vector2 limbPos = MainLimb.SimPosition - Vector2.Normalize(movement) * dist;
|
||||
|
||||
Limbs[i].body.ApplyForce(((limbPos - Limbs[i].SimPosition) * 3.0f - Limbs[i].LinearVelocity * 3.0f) * Limbs[i].Mass);
|
||||
}
|
||||
@@ -233,7 +220,7 @@ namespace Barotrauma
|
||||
IgnorePlatforms = (TargetMovement.Y < -Math.Abs(TargetMovement.X));
|
||||
|
||||
float mainLimbHeight, mainLimbAngle;
|
||||
if (mainLimb.type == LimbType.Torso)
|
||||
if (MainLimb.type == LimbType.Torso)
|
||||
{
|
||||
mainLimbHeight = TorsoPosition;
|
||||
mainLimbAngle = torsoAngle;
|
||||
@@ -244,18 +231,18 @@ namespace Barotrauma
|
||||
mainLimbAngle = headAngle;
|
||||
}
|
||||
|
||||
mainLimb.body.SmoothRotate(mainLimbAngle * Dir, 50.0f);
|
||||
MainLimb.body.SmoothRotate(mainLimbAngle * Dir, 50.0f);
|
||||
|
||||
collider.LinearVelocity = new Vector2(
|
||||
movement.X,
|
||||
collider.LinearVelocity.Y > 0.0f ? collider.LinearVelocity.Y * 0.5f : collider.LinearVelocity.Y);
|
||||
|
||||
mainLimb.MoveToPos(GetColliderBottom() + Vector2.UnitY * mainLimbHeight, 10.0f);
|
||||
MainLimb.MoveToPos(GetColliderBottom() + Vector2.UnitY * mainLimbHeight, 10.0f);
|
||||
|
||||
mainLimb.pullJoint.Enabled = true;
|
||||
mainLimb.pullJoint.WorldAnchorB = GetColliderBottom() + Vector2.UnitY * mainLimbHeight;
|
||||
MainLimb.pullJoint.Enabled = true;
|
||||
MainLimb.pullJoint.WorldAnchorB = GetColliderBottom() + Vector2.UnitY * mainLimbHeight;
|
||||
|
||||
walkPos -= mainLimb.LinearVelocity.X * 0.05f;
|
||||
walkPos -= MainLimb.LinearVelocity.X * 0.05f;
|
||||
|
||||
Vector2 transformedStepSize = new Vector2(
|
||||
(float)Math.Cos(walkPos) * stepSize.X * 3.0f,
|
||||
@@ -267,7 +254,7 @@ namespace Barotrauma
|
||||
{
|
||||
case LimbType.LeftFoot:
|
||||
case LimbType.RightFoot:
|
||||
Vector2 footPos = new Vector2(limb.SimPosition.X, mainLimb.SimPosition.Y - mainLimbHeight);
|
||||
Vector2 footPos = new Vector2(limb.SimPosition.X, MainLimb.SimPosition.Y - mainLimbHeight);
|
||||
|
||||
if (limb.RefJointIndex>-1)
|
||||
{
|
||||
|
||||
@@ -61,10 +61,11 @@ namespace Barotrauma
|
||||
|
||||
public override void UpdateAnim(float deltaTime)
|
||||
{
|
||||
if (character.IsDead || Frozen || character.IsUnconscious || stunTimer > 0.0f)
|
||||
if (Frozen) return;
|
||||
|
||||
if (character.IsDead || character.IsUnconscious || stunTimer > 0.0f)
|
||||
{
|
||||
collider.PhysEnabled = false;
|
||||
|
||||
collider.SetTransform(GetLimb(LimbType.Torso).SimPosition, 0.0f);
|
||||
|
||||
if (stunTimer > 0)
|
||||
@@ -97,9 +98,7 @@ namespace Barotrauma
|
||||
0.0f);
|
||||
|
||||
collider.FarseerBody.Enabled = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (swimming)
|
||||
{
|
||||
@@ -146,12 +145,6 @@ namespace Barotrauma
|
||||
|
||||
HandIK(rightHand, midPos);
|
||||
HandIK(leftHand, midPos);
|
||||
|
||||
//rightHand.pullJoint.Enabled = true;
|
||||
//rightHand.pullJoint.WorldAnchorB = midPos;
|
||||
|
||||
//rightHand.pullJoint.Enabled = true;
|
||||
//rightHand.pullJoint.WorldAnchorB = midPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -310,8 +303,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
//if (LowestLimb == null) return;
|
||||
|
||||
if (onGround && (!character.IsRemotePlayer || GameMain.Server != null))
|
||||
{
|
||||
collider.LinearVelocity = new Vector2(
|
||||
@@ -319,14 +310,6 @@ namespace Barotrauma
|
||||
collider.LinearVelocity.Y > 0.0f ? collider.LinearVelocity.Y * 0.5f : collider.LinearVelocity.Y);
|
||||
}
|
||||
|
||||
//float? ceilingY = null;
|
||||
//if (Submarine.PickBody(head.SimPosition, head.SimPosition + Vector2.UnitY, null, Physics.CollisionWall)!=null)
|
||||
//{
|
||||
// ceilingY = Submarine.LastPickedPosition.Y;
|
||||
|
||||
// if (ceilingY - floorY < HeadPosition) Crouching = true;
|
||||
//}
|
||||
|
||||
getUpSpeed = getUpSpeed * Math.Max(head.SimPosition.Y - colliderPos.Y, 0.5f);
|
||||
|
||||
torso.pullJoint.Enabled = true;
|
||||
@@ -585,14 +568,7 @@ namespace Barotrauma
|
||||
//pull head above water
|
||||
head.body.SmoothRotate(0.0f, 5.0f);
|
||||
|
||||
|
||||
walkPos += 0.05f;
|
||||
|
||||
//push feet downwards
|
||||
//leftFoot.body.ApplyForce(leftFoot.Mass * new Vector2(0.0f, -50.0f));
|
||||
// rightFoot.body.ApplyForce(rightFoot.Mass * new Vector2(0.0f, -50.0f));
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -98,6 +98,12 @@ namespace Barotrauma
|
||||
private set;
|
||||
}
|
||||
|
||||
public Limb MainLimb
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public Vector2 WorldPosition
|
||||
{
|
||||
get
|
||||
@@ -313,6 +319,11 @@ namespace Barotrauma
|
||||
{
|
||||
limb.sprite.Depth = startDepth + limb.sprite.Depth * 0.0001f;
|
||||
}
|
||||
|
||||
Limb torso = GetLimb(LimbType.Torso);
|
||||
Limb head = GetLimb(LimbType.Head);
|
||||
|
||||
MainLimb = torso == null ? head : torso;
|
||||
}
|
||||
|
||||
public void AddJoint(XElement subElement, float scale = 1.0f)
|
||||
@@ -702,7 +713,7 @@ namespace Barotrauma
|
||||
SetPosition(collider.SimPosition + moveAmount);
|
||||
character.CursorPosition += moveAmount;
|
||||
}
|
||||
|
||||
|
||||
private void UpdateCollisionCategories()
|
||||
{
|
||||
Category wall = currentHull == null ?
|
||||
@@ -732,11 +743,10 @@ namespace Barotrauma
|
||||
|
||||
public void Update(Camera cam, float deltaTime)
|
||||
{
|
||||
if (!character.Enabled) return;
|
||||
|
||||
if (Frozen) return;
|
||||
if (!character.Enabled || Frozen) return;
|
||||
|
||||
UpdateNetPlayerPosition(deltaTime);
|
||||
CheckDistFromCollider();
|
||||
|
||||
Vector2 flowForce = Vector2.Zero;
|
||||
|
||||
@@ -1025,25 +1035,30 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
//public void SetRotation(float rotation)
|
||||
//{
|
||||
// float rotateAmount = rotation - refLimb.Rotation;
|
||||
|
||||
// Matrix rotationMatrix = Matrix.CreateRotationZ(rotateAmount);
|
||||
private bool collisionsDisabled;
|
||||
|
||||
// refLimb.body.SetTransform(refLimb.SimPosition, rotation);
|
||||
protected void CheckDistFromCollider()
|
||||
{
|
||||
float allowedDist = Math.Max(Math.Max(collider.radius, collider.width), collider.height);
|
||||
|
||||
// foreach (Limb limb in Limbs)
|
||||
// {
|
||||
// if (limb == refLimb) continue;
|
||||
//if the ragdoll is too far from the collider, disable collisions until it's close enough
|
||||
//(in case the ragdoll has gotten stuck somewhere)
|
||||
if (Vector2.Distance(collider.SimPosition, MainLimb.SimPosition) > allowedDist)
|
||||
{
|
||||
foreach (Limb limb in Limbs)
|
||||
{
|
||||
limb.body.CollidesWith = Physics.CollisionNone;
|
||||
}
|
||||
|
||||
// Vector2 newPos = limb.SimPosition - refLimb.SimPosition;
|
||||
// newPos = Vector2.Transform(newPos, rotationMatrix);
|
||||
|
||||
// TrySetLimbPosition(limb, refLimb.SimPosition, refLimb.SimPosition + newPos);
|
||||
// limb.body.SetTransform(limb.SimPosition, limb.Rotation + rotateAmount);
|
||||
// }
|
||||
//}
|
||||
collisionsDisabled = true;
|
||||
}
|
||||
else if (collisionsDisabled)
|
||||
{
|
||||
UpdateCollisionCategories();
|
||||
collisionsDisabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
float t = 0.0f;
|
||||
|
||||
@@ -1068,41 +1083,41 @@ namespace Barotrauma
|
||||
|
||||
if (character.MemLocalPos.Count > 120) character.MemLocalPos.RemoveRange(0, character.MemLocalPos.Count - 120);
|
||||
character.MemPos.Clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PosInfo prev = character.MemPos[0];
|
||||
PosInfo next = character.MemPos[1];
|
||||
|
||||
Vector2 currPos = collider.SimPosition;
|
||||
|
||||
//interpolate the position of the collider from the first position in the buffer towards the second
|
||||
if (prev.Timestamp < next.Timestamp)
|
||||
{
|
||||
//if there are more than 2 positions in the buffer,
|
||||
//increase the interpolation speed to catch up with the server
|
||||
float speedMultiplier = 1.0f + (float)Math.Pow((character.MemPos.Count - 2) / 2.0f, 2.0f);
|
||||
|
||||
t += (deltaTime * speedMultiplier) / (next.Timestamp - prev.Timestamp);
|
||||
currPos = Vector2.Lerp(prev.Position, next.Position, t);
|
||||
|
||||
//override the targetMovement to make the character play the walking/running animation
|
||||
overrideTargetMovement = (next.Position - prev.Position) / (next.Timestamp - prev.Timestamp);
|
||||
}
|
||||
else
|
||||
{
|
||||
currPos = next.Position;
|
||||
t = 1.0f;
|
||||
}
|
||||
|
||||
collider.SetTransform(currPos, collider.Rotation);
|
||||
PosInfo prev = character.MemPos[0];
|
||||
PosInfo next = character.MemPos[1];
|
||||
|
||||
if (t >= 1.0f)
|
||||
{
|
||||
t = 0.0f;
|
||||
character.MemPos.RemoveAt(0);
|
||||
}
|
||||
Vector2 currPos = collider.SimPosition;
|
||||
|
||||
//interpolate the position of the collider from the first position in the buffer towards the second
|
||||
if (prev.Timestamp < next.Timestamp)
|
||||
{
|
||||
//if there are more than 2 positions in the buffer,
|
||||
//increase the interpolation speed to catch up with the server
|
||||
float speedMultiplier = 1.0f + (float)Math.Pow((character.MemPos.Count - 2) / 2.0f, 2.0f);
|
||||
|
||||
t += (deltaTime * speedMultiplier) / (next.Timestamp - prev.Timestamp);
|
||||
currPos = Vector2.Lerp(prev.Position, next.Position, t);
|
||||
|
||||
//override the targetMovement to make the character play the walking/running animation
|
||||
overrideTargetMovement = (next.Position - prev.Position) / (next.Timestamp - prev.Timestamp);
|
||||
}
|
||||
else
|
||||
{
|
||||
currPos = next.Position;
|
||||
t = 1.0f;
|
||||
}
|
||||
|
||||
collider.SetTransform(currPos, collider.Rotation);
|
||||
|
||||
if (t >= 1.0f)
|
||||
{
|
||||
t = 0.0f;
|
||||
character.MemPos.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Vector2 EstimateCurrPosition(Vector2 prevPosition, float timePassed)
|
||||
|
||||
@@ -475,7 +475,7 @@ namespace Barotrauma
|
||||
|
||||
public override Vector2 DrawPosition
|
||||
{
|
||||
get { return AnimController.Collider.DrawPosition; }
|
||||
get { return AnimController.MainLimb.body.DrawPosition; }
|
||||
}
|
||||
|
||||
public delegate void OnDeathHandler(Character character, CauseOfDeath causeOfDeath);
|
||||
|
||||
@@ -341,8 +341,6 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
body.SetTransform(targetPosition, targetRotation == 0.0f ? body.Rotation : targetRotation);
|
||||
//body.LinearVelocity = targetVelocity;
|
||||
//body.AngularVelocity = targetAngularVelocity;
|
||||
targetPosition = Vector2.Zero;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user