Changed colliders from limbs to normal physics bodies, removed RefLimb

This commit is contained in:
Regalis
2016-10-15 20:08:51 +03:00
parent 1b59d1bc21
commit db8c2b9f8e
12 changed files with 317 additions and 298 deletions
@@ -73,7 +73,7 @@ namespace Barotrauma
}
else
{
if (inWater || RefLimb.inWater)
if (inWater)// || RefLimb.inWater)
{
UpdateSineAnim(deltaTime);
}
@@ -224,25 +224,27 @@ namespace Barotrauma
void UpdateSimpleAnim()
{
movement = MathUtils.SmoothStep(movement, TargetMovement*swimSpeed, 1.0f);
if (movement == Vector2.Zero) return;
//todo: reimplement
float movementAngle = MathUtils.VectorToAngle(movement) - MathHelper.PiOver2;
//movement = MathUtils.SmoothStep(movement, TargetMovement*swimSpeed, 1.0f);
//if (movement == Vector2.Zero) return;
//float movementAngle = MathUtils.VectorToAngle(movement) - MathHelper.PiOver2;
RefLimb.body.SmoothRotate(
(rotateTowardsMovement) ?
RefLimb.body.Rotation + MathUtils.GetShortestAngle(RefLimb.body.Rotation, movementAngle) :
HeadAngle*Dir);
//RefLimb.body.SmoothRotate(
// (rotateTowardsMovement) ?
// RefLimb.body.Rotation + MathUtils.GetShortestAngle(RefLimb.body.Rotation, movementAngle) :
// HeadAngle*Dir);
RefLimb.body.LinearVelocity = movement;
//collider.LinearVelocity = movement;
//RefLimb.body.SmoothRotate(0.0f);
////RefLimb.body.SmoothRotate(0.0f);
foreach (Limb l in Limbs)
{
if (l == RefLimb) continue;
l.body.SetTransform(RefLimb.SimPosition, RefLimb.Rotation);
}
//foreach (Limb l in Limbs)
//{
// if (l == RefLimb) continue;
// l.body.SetTransform(RefLimb.SimPosition, RefLimb.Rotation);
//}
}
void UpdateWalkAnim(float deltaTime)
@@ -344,7 +346,7 @@ namespace Barotrauma
if (Math.Abs(colliderPos.Y - floorY) < colliderHeight * 1.2f)
{
colliderLimb.Move(new Vector2(colliderPos.X + movement.X * 0.2f, floorY + colliderHeight), 5.0f);
colliderLimb.MoveToPos(new Vector2(colliderPos.X + movement.X * 0.2f, floorY + colliderHeight), 5.0f);
}
float walkCycleSpeed = head.LinearVelocity.X * 0.05f;
@@ -373,14 +375,14 @@ namespace Barotrauma
if (limb.type == LimbType.LeftFoot)
{
limb.Move(footPos +new Vector2(
limb.MoveToPos(footPos +new Vector2(
transformedStepSize.X + movement.X * 0.1f,
(transformedStepSize.Y > 0.0f) ? transformedStepSize.Y : 0.0f),
8.0f);
}
else if (limb.type == LimbType.RightFoot)
{
limb.Move(footPos +new Vector2(
limb.MoveToPos(footPos +new Vector2(
-transformedStepSize.X + movement.X * 0.1f,
(-transformedStepSize.Y > 0.0f) ? -transformedStepSize.Y : 0.0f),
8.0f);
@@ -63,11 +63,10 @@ namespace Barotrauma
{
if (character.IsDead || Frozen || character.IsUnconscious || stunTimer > 0.0f)
{
collider.Disabled = true;
collider.body.PhysEnabled = false;
collider.PhysEnabled = false;
var lowestLimb = FindLowestLimb(true);
collider.body.SetTransform(GetLimb(LimbType.Torso).SimPosition, 0.0f);
var lowestLimb = FindLowestLimb();
collider.SetTransform(GetLimb(LimbType.Torso).SimPosition, 0.0f);
if (stunTimer > 0)
{
@@ -77,7 +76,14 @@ namespace Barotrauma
return;
}
if (collider == null) return;
//stun (= disable the animations) if the ragdoll receives a large enough impact
if (strongestImpact > 0.0f)
{
character.StartStun(MathHelper.Min(strongestImpact * 0.5f, 5.0f));
strongestImpact = 0.0f;
return;
}
//if (inWater) stairs = null;
@@ -153,8 +159,8 @@ namespace Barotrauma
bool onStairs = stairs != null;
stairs = null;
var contacts = collider.body.FarseerBody.ContactList;
while (collider.body.PhysEnabled && contacts != null && contacts.Contact != null)
var contacts = collider.FarseerBody.ContactList;
while (collider.FarseerBody.Enabled && contacts != null && contacts.Contact != null)
{
if (contacts.Contact.Enabled && contacts.Contact.IsTouching)
{
@@ -219,18 +225,13 @@ namespace Barotrauma
onFloorTimer -= deltaTime;
}
//stun (= disable the animations) if the ragdoll receives a large enough impact
if (strongestImpact > 0.0f)
{
character.StartStun(MathHelper.Min(strongestImpact * 0.5f, 5.0f));
}
strongestImpact = 0.0f;
if (collider.Disabled && !swimming)
//re-enable collider (unless swimming)
if (!collider.FarseerBody.Enabled && !swimming)
{
var lowestLimb = FindLowestLimb(true);
collider.body.SetTransform(lowestLimb.SimPosition + Vector2.UnitY * (collider.body.radius + collider.body.height / 2), 0.0f);
collider.Disabled = false;
var lowestLimb = FindLowestLimb();
collider.SetTransform(lowestLimb.SimPosition + Vector2.UnitY * (collider.radius + collider.height / 2), 0.0f);
collider.FarseerBody.Enabled = true;
}
if (character.LockHands)
@@ -274,12 +275,8 @@ namespace Barotrauma
UpdateStandingSimple();
return;
}
collider.body.PhysEnabled = true;
collider.body.Enabled = true;
switch (Anim)
{
case Animation.Climbing:
@@ -324,7 +321,6 @@ namespace Barotrauma
foreach (Limb limb in Limbs)
{
if (limb == collider) continue;
limb.Disabled = false;
}
@@ -430,7 +426,7 @@ namespace Barotrauma
if (onGround)
{
collider.body.LinearVelocity = new Vector2(
collider.LinearVelocity = new Vector2(
movement.X * 1.5f,
collider.LinearVelocity.Y > 0.0f ? collider.LinearVelocity.Y * 0.5f : collider.LinearVelocity.Y);
}
@@ -483,7 +479,6 @@ namespace Barotrauma
foreach (Limb limb in Limbs)
{
if (limb == collider) continue;
MoveLimb(limb, limb.SimPosition+move, 15.0f, true);
}
@@ -635,9 +630,8 @@ namespace Barotrauma
Limb head = GetLimb(LimbType.Head);
Limb torso = GetLimb(LimbType.Torso);
collider.body.PhysEnabled = false;
collider.Disabled = true;
collider.body.SetTransform(torso.SimPosition, 0.0f);
collider.FarseerBody.Enabled = false;
collider.SetTransform(torso.SimPosition, 0.0f);
if (currentHull != null && (currentHull.Rect.Y - currentHull.Surface > 50.0f) && !head.inWater)
{
@@ -856,9 +850,8 @@ namespace Barotrauma
MoveLimb(torso, new Vector2(ladderSimPos.X - 0.27f * Dir, collider.SimPosition.Y+0.5f), 10.5f);
MoveLimb(waist, new Vector2(ladderSimPos.X - 0.35f * Dir, collider.SimPosition.Y+0.4f), 10.5f);
MoveLimb(collider, new Vector2(ladderSimPos.X - 0.2f * Dir, collider.SimPosition.Y), 10.5f);
collider.MoveToPos(new Vector2(ladderSimPos.X - 0.2f * Dir, collider.SimPosition.Y), 10.5f);
Vector2 handPos = new Vector2(
ladderSimPos.X,
collider.SimPosition.Y + 0.6f + movement.Y * 0.1f - ladderSimPos.Y);
@@ -901,7 +894,6 @@ namespace Barotrauma
leftLeg.body.ApplyTorque(Dir * -8.0f);
rightLeg.body.ApplyTorque(Dir * -8.0f);
//apply forces to the head and the torso to move the Character up/down
float movementFactor = (handPos.Y / stepHeight) * (float)Math.PI;
movementFactor = 0.8f + (float)Math.Abs(Math.Sin(movementFactor));
@@ -911,7 +903,8 @@ namespace Barotrauma
Vector2 climbForce = new Vector2(0.0f, movement.Y + 0.3f) * movementFactor;
//if (climbForce.Y > 0.5f) climbForce.Y = Math.Max(climbForce.Y, 1.3f);
collider.body.ApplyForce((climbForce * 20.0f + subSpeed * 50.0f) * collider.Mass);
//apply forces to the collider to move the Character up/down
collider.ApplyForce((climbForce * 20.0f + subSpeed * 50.0f) * collider.Mass);
head.body.SmoothRotate(0.0f);
if (!character.SelectedConstruction.Prefab.Triggers.Any())
@@ -1313,7 +1306,7 @@ namespace Barotrauma
float angle = flipAngle ? -limb.body.Rotation : limb.body.Rotation;
if (wrapAngle) angle = MathUtils.WrapAnglePi(angle);
TrySetLimbPosition(limb, RefLimb.SimPosition, position);
TrySetLimbPosition(limb, collider.SimPosition, position);
limb.body.SetTransform(limb.body.SimPosition, angle);
}
+185 -172
View File
@@ -20,8 +20,23 @@ namespace Barotrauma
public Limb[] Limbs;
private bool isFrozen = false;
public bool Frozen = false;
private bool frozen;
public bool Frozen
{
get { return frozen; }
set
{
if (frozen == value) return;
frozen = value;
foreach (Limb l in Limbs)
{
l.body.PhysEnabled = frozen;
}
collider.PhysEnabled = frozen;
}
}
private Dictionary<LimbType, Limb> limbDictionary;
public RevoluteJoint[] limbJoints;
@@ -54,22 +69,20 @@ namespace Barotrauma
protected bool inWater, headInWater;
public bool onGround;
private bool ignorePlatforms;
protected Limb refLimb;
protected Structure stairs;
protected Direction dir;
public Direction TargetDir;
protected Limb collider;
protected PhysicsBody collider;
public Limb RefLimb
public PhysicsBody Collider
{
get
{
return refLimb;
return collider;
}
}
@@ -84,26 +97,39 @@ namespace Barotrauma
private set;
}
public Vector2 WorldPosition
{
get
{
return character.Submarine == null ?
ConvertUnits.ToDisplayUnits(collider.SimPosition) :
ConvertUnits.ToDisplayUnits(collider.SimPosition) + character.Submarine.Position;
}
}
public bool SimplePhysicsEnabled
{
get { return simplePhysicsEnabled; }
set
{
if (value == simplePhysicsEnabled) return;
//TODO: reimplement
return;
//if (value == simplePhysicsEnabled) return;
simplePhysicsEnabled = value;
//simplePhysicsEnabled = value;
foreach (Limb limb in Limbs)
{
limb.body.Enabled = !simplePhysicsEnabled;
}
//foreach (Limb limb in Limbs)
//{
// limb.body.Enabled = !simplePhysicsEnabled;
//}
foreach (RevoluteJoint joint in limbJoints)
{
joint.Enabled = !simplePhysicsEnabled;
}
//foreach (RevoluteJoint joint in limbJoints)
//{
// joint.Enabled = !simplePhysicsEnabled;
//}
refLimb.body.Enabled = true;
//refLimb.body.Enabled = true;
}
}
@@ -166,10 +192,12 @@ namespace Barotrauma
if (value == currentHull) return;
currentHull = value;
Submarine currSubmarine = currentHull == null ? null : currentHull.Submarine;
foreach (Limb limb in Limbs)
{
limb.body.Submarine = currentHull == null ? null : currentHull.Submarine;
limb.body.Submarine = currSubmarine;
}
collider.Submarine = currSubmarine;
}
}
@@ -240,20 +268,28 @@ namespace Barotrauma
case "joint":
AddJoint(subElement, scale);
break;
case "collider":
collider = new PhysicsBody(subElement, scale);
collider.FarseerBody.FixedRotation = true;
break;
}
}
refLimb = GetLimb(LimbType.Torso);
if (refLimb == null) refLimb = GetLimb(LimbType.Head);
if (refLimb == null) DebugConsole.ThrowError("Character \"" + character + "\" doesn't have a head or torso!");
if (collider == null)
{
DebugConsole.ThrowError("No collider configured for ''"+character.Name+"''!");
collider = new PhysicsBody(0.0f, 0.0f, 16.0f, 5.0f);
}
collider.CollisionCategories = Physics.CollisionCharacter;
collider.FarseerBody.FixedRotation = true;
collider.FarseerBody.OnCollision += OnLimbCollision;
UpdateCollisionCategories();
foreach (var joint in limbJoints)
{
joint.BodyB.SetTransform(
joint.BodyA.Position + (joint.LocalAnchorA - joint.LocalAnchorB)*0.1f,
(joint.LowerLimit + joint.UpperLimit) / 2.0f);
@@ -272,13 +308,6 @@ namespace Barotrauma
{
limb.sprite.Depth = startDepth + limb.sprite.Depth * 0.0001f;
}
collider = GetLimb(LimbType.Collider);
if (collider == null) return;
collider.body.FarseerBody.FixedRotation = true;
collider.pullJoint = null;
refLimb = collider;
}
public void AddJoint(XElement subElement, float scale = 1.0f)
@@ -443,33 +472,35 @@ namespace Barotrauma
// avgVelocity += limb.LinearVelocity;
//}
Limb limb = (Limb)f1.Body.UserData;
Vector2 velocity = limb.LinearVelocity;
Vector2 velocity = f1.Body.LinearVelocity;
if (character.Submarine == null && f2.Body.UserData is Submarine) velocity -= ((Submarine)f2.Body.UserData).Velocity;
float impact = Vector2.Dot(velocity, -normal);
float volume = stairs == null ? impact / 5.0f : impact;
volume = Math.Min(impact, 1.0f);
if (impact > 0.5f && limb.HitSound != null && limb.soundTimer <= 0.0f)
if (f1.Body.UserData is Limb)
{
limb.soundTimer = Limb.SoundInterval;
limb.HitSound.Play(volume, impact * 250.0f, limb.WorldPosition);
}
Limb limb = (Limb)f1.Body.UserData;
if (impact > limb.impactTolerance && limb == collider)
float volume = stairs == null ? impact / 5.0f : impact;
volume = Math.Min(impact, 1.0f);
if (impact > 0.5f && limb.HitSound != null && limb.soundTimer <= 0.0f)
{
limb.soundTimer = Limb.SoundInterval;
limb.HitSound.Play(volume, impact * 250.0f, limb.WorldPosition);
}
}
else if (f1.Body == collider.FarseerBody)
{
if (!character.IsNetworkPlayer || GameMain.Server != null)
{
character.AddDamage(CauseOfDeath.Damage, impact - limb.impactTolerance * 0.1f, null);
strongestImpact = Math.Max(strongestImpact, impact - limb.impactTolerance);
character.AddDamage(CauseOfDeath.Damage, impact - 8.0f, null);
strongestImpact = Math.Max(strongestImpact, impact - 8.0f);
}
SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, limb.body);
SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, collider);
if (Character.Controlled == character) GameMain.GameScreen.Cam.Shake = strongestImpact;
}
@@ -478,6 +509,8 @@ namespace Barotrauma
public virtual void Draw(SpriteBatch spriteBatch)
{
if (simplePhysicsEnabled) return;
collider.UpdateDrawPosition();
foreach (Limb limb in Limbs)
{
@@ -508,8 +541,14 @@ namespace Barotrauma
//GUI.DrawLine(spriteBatch, pos, pos2, Color.Green);
}
limb.body.DebugDraw(spriteBatch, character.Submarine == null ? Color.Cyan : Color.White);
}
collider.DebugDraw(spriteBatch, character.Submarine == null ? Color.Cyan : Color.White);
foreach (RevoluteJoint joint in limbJoints)
{
Vector2 pos = ConvertUnits.ToDisplayUnits(joint.WorldAnchorA);
@@ -528,13 +567,16 @@ namespace Barotrauma
pos.Y = -pos.Y;
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X - 10, (int)pos.Y - 10, 20, 20), Color.Cyan, false, 0.01f);
GUI.DrawLine(spriteBatch, pos, new Vector2(limb.WorldPosition.X, -limb.WorldPosition.Y), limb == RefLimb ? Color.Orange : Color.Cyan);
GUI.DrawLine(spriteBatch, pos, new Vector2(limb.WorldPosition.X, -limb.WorldPosition.Y), Color.Cyan);
}
}
if (ignorePlatforms)
{
GUI.DrawLine(spriteBatch, new Vector2(refLimb.WorldPosition.X, -refLimb.WorldPosition.Y), new Vector2(refLimb.WorldPosition.X, -refLimb.WorldPosition.Y+50), Color.Orange, 0, 5);
GUI.DrawLine(spriteBatch,
new Vector2(collider.DrawPosition.X, -collider.DrawPosition.Y),
new Vector2(collider.DrawPosition.X, -collider.DrawPosition.Y + 50),
Color.Orange, 0, 5);
}
}
@@ -587,20 +629,16 @@ namespace Barotrauma
return centerOfMass;
}
/// <summary>
///
/// </summary>
/// <param name="pullFromCenter">if false, force is applied to the position of pullJoint</param>
protected void MoveLimb(Limb limb, Vector2 pos, float amount, bool pullFromCenter = false)
{
limb.Move(pos, amount, pullFromCenter);
limb.MoveToPos(pos, amount, pullFromCenter);
}
public void ResetPullJoints()
{
for (int i = 0; i < Limbs.Count(); i++)
for (int i = 0; i < Limbs.Length; i++)
{
if (Limbs[i] == null || Limbs[i].pullJoint == null) continue;
Limbs[i].pullJoint.Enabled = false;
@@ -622,7 +660,7 @@ namespace Barotrauma
return;
}
Vector2 findPos = worldPosition==null ? refLimb.WorldPosition : (Vector2)worldPosition;
Vector2 findPos = worldPosition==null ? this.WorldPosition : (Vector2)worldPosition;
Hull newHull = Hull.FindHull(findPos, currentHull);
@@ -674,7 +712,6 @@ namespace Barotrauma
while (ce != null && ce.Contact != null)
{
ce.Contact.Enabled = false;
ce = ce.Next;
}
}
@@ -687,7 +724,7 @@ namespace Barotrauma
//character.Stun = 0.1f;
character.DisableImpactDamageTimer = 0.25f;
SetPosition(refLimb.SimPosition + moveAmount);
SetPosition(collider.SimPosition + moveAmount);
character.CursorPosition += moveAmount;
}
@@ -701,6 +738,8 @@ namespace Barotrauma
wall | Physics.CollisionProjectile | Physics.CollisionStairs
: wall | Physics.CollisionProjectile | Physics.CollisionPlatform | Physics.CollisionStairs;
collider.CollidesWith = collisionCategory;
foreach (Limb limb in Limbs)
{
if (limb.ignoreCollisions) continue;
@@ -720,26 +759,7 @@ namespace Barotrauma
{
if (!character.Enabled) return;
if (Frozen)
{
if (!isFrozen)
{
foreach (Limb l in Limbs)
{
l.body.PhysEnabled = false;
}
isFrozen = true;
}
return;
}
if (isFrozen)
{
foreach (Limb l in Limbs)
{
l.body.PhysEnabled = true;
}
isFrozen = false;
}
if (Frozen) return;
UpdateNetPlayerPosition();
@@ -845,22 +865,16 @@ namespace Barotrauma
public void SetPosition(Vector2 simPosition, bool lerp = false)
{
Vector2 moveAmount = simPosition - refLimb.SimPosition;
Vector2 moveAmount = simPosition - collider.SimPosition;
collider.SetTransform(simPosition, collider.Rotation);
foreach (Limb limb in Limbs)
{
if (limb == refLimb)
{
TrySetLimbPosition(limb, simPosition, simPosition, lerp);
}
else
{
//check visibility from the new position of RefLimb to the new position of this limb
Vector2 movePos = limb.SimPosition + moveAmount;
TrySetLimbPosition(limb, simPosition, movePos, lerp);
}
//check visibility from the new position of the collider to the new position of this limb
Vector2 movePos = limb.SimPosition + moveAmount;
TrySetLimbPosition(limb, simPosition, movePos, lerp);
}
}
@@ -899,110 +913,110 @@ namespace Barotrauma
}
}
public void SetRotation(float rotation)
{
float rotateAmount = rotation - refLimb.Rotation;
//public void SetRotation(float rotation)
//{
// float rotateAmount = rotation - refLimb.Rotation;
Matrix rotationMatrix = Matrix.CreateRotationZ(rotateAmount);
// Matrix rotationMatrix = Matrix.CreateRotationZ(rotateAmount);
refLimb.body.SetTransform(refLimb.SimPosition, rotation);
// refLimb.body.SetTransform(refLimb.SimPosition, rotation);
foreach (Limb limb in Limbs)
{
if (limb == refLimb) continue;
// foreach (Limb limb in Limbs)
// {
// if (limb == refLimb) continue;
Vector2 newPos = limb.SimPosition - refLimb.SimPosition;
newPos = Vector2.Transform(newPos, rotationMatrix);
// 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);
}
}
// TrySetLimbPosition(limb, refLimb.SimPosition, refLimb.SimPosition + newPos);
// limb.body.SetTransform(limb.SimPosition, limb.Rotation + rotateAmount);
// }
//}
private void UpdateNetPlayerPosition()
{
if (refLimb.body.TargetPosition == Vector2.Zero)
{
correctionMovement = Vector2.Zero;
return;
}
//if (refLimb.body.TargetPosition == Vector2.Zero)
//{
// correctionMovement = Vector2.Zero;
// return;
//}
//if the limb is closer than alloweddistance, just ignore the difference
float allowedDistance = NetConfig.AllowedRagdollDistance * ((inWater) ? 2.0f : 1.0f);
////if the limb is closer than alloweddistance, just ignore the difference
//float allowedDistance = NetConfig.AllowedRagdollDistance * ((inWater) ? 2.0f : 1.0f);
if (currentHull == null)
{
var overLappingHull = Hull.FindHull(ConvertUnits.ToDisplayUnits(refLimb.body.TargetPosition), null, true);
//if (currentHull == null)
//{
// var overLappingHull = Hull.FindHull(ConvertUnits.ToDisplayUnits(refLimb.body.TargetPosition), null, true);
if (overLappingHull != null)
{
Submarine.PickBody(refLimb.SimPosition, refLimb.body.TargetPosition, null, Physics.CollisionWall);
// if (overLappingHull != null)
// {
// Submarine.PickBody(refLimb.SimPosition, refLimb.body.TargetPosition, null, Physics.CollisionWall);
refLimb.body.TargetPosition = refLimb.SimPosition + (refLimb.body.TargetPosition - refLimb.SimPosition) * Submarine.LastPickedFraction * 0.9f;
}
}
// refLimb.body.TargetPosition = refLimb.SimPosition + (refLimb.body.TargetPosition - refLimb.SimPosition) * Submarine.LastPickedFraction * 0.9f;
// }
//}
float dist = Vector2.Distance(refLimb.body.SimPosition, refLimb.body.TargetPosition);
//float dist = Vector2.Distance(refLimb.body.SimPosition, refLimb.body.TargetPosition);
//if the limb is further away than resetdistance, all limbs are immediately snapped to their targetpositions
bool resetAll = dist > NetConfig.ResetRagdollDistance;
////if the limb is further away than resetdistance, all limbs are immediately snapped to their targetpositions
//bool resetAll = dist > NetConfig.ResetRagdollDistance;
Vector2 diff = (refLimb.body.TargetPosition - refLimb.body.SimPosition);
//Vector2 diff = (refLimb.body.TargetPosition - refLimb.body.SimPosition);
if (diff == Vector2.Zero || diff.Length() < allowedDistance)
{
refLimb.body.TargetPosition = Vector2.Zero;
foreach (Limb limb in Limbs)
{
limb.body.TargetPosition = Vector2.Zero;
}
//if (diff == Vector2.Zero || diff.Length() < allowedDistance)
//{
// refLimb.body.TargetPosition = Vector2.Zero;
// foreach (Limb limb in Limbs)
// {
// limb.body.TargetPosition = Vector2.Zero;
// }
correctionMovement = Vector2.Zero;
return;
}
// correctionMovement = Vector2.Zero;
// return;
//}
if (resetAll)
{
System.Diagnostics.Debug.WriteLine("reset ragdoll limb positions");
//if (resetAll)
//{
// System.Diagnostics.Debug.WriteLine("reset ragdoll limb positions");
SetPosition(refLimb.body.TargetPosition, dist < 10.0f);
// SetPosition(refLimb.body.TargetPosition, dist < 10.0f);
return;
}
// return;
//}
if (inWater)
{
if (targetMovement.LengthSquared() > 0.01f)
{
correctionMovement =
Vector2.Lerp(targetMovement, Vector2.Normalize(diff) * MathHelper.Clamp(dist * 5.0f, 0.1f, 5.0f), 0.2f);
//if (inWater)
//{
// if (targetMovement.LengthSquared() > 0.01f)
// {
// correctionMovement =
// Vector2.Lerp(targetMovement, Vector2.Normalize(diff) * MathHelper.Clamp(dist * 5.0f, 0.1f, 5.0f), 0.2f);
}
else
{
refLimb.body.LinearVelocity = Vector2.Lerp(
refLimb.LinearVelocity,
Vector2.Normalize(diff) * MathHelper.Clamp(dist, 0.0f, 5.0f),
0.2f);
}
}
else
{
//clamp the magnitude of the correction movement between 0.5f - 5.0f
Vector2 newCorrectionMovement = Vector2.Normalize(diff) * MathHelper.Clamp(dist * 2.0f, 0.5f, 5.0f);
// }
// else
// {
// refLimb.body.LinearVelocity = Vector2.Lerp(
// refLimb.LinearVelocity,
// Vector2.Normalize(diff) * MathHelper.Clamp(dist, 0.0f, 5.0f),
// 0.2f);
// }
//}
//else
//{
// //clamp the magnitude of the correction movement between 0.5f - 5.0f
// Vector2 newCorrectionMovement = Vector2.Normalize(diff) * MathHelper.Clamp(dist * 2.0f, 0.5f, 5.0f);
//heading in the right direction -> use the \"normal\" movement if it's faster than correctionMovement
//i.e. the character is close to the targetposition but the character is still running
if (Math.Sign(targetMovement.X) == Math.Sign(newCorrectionMovement.X))
{
newCorrectionMovement.X = Math.Max(Math.Abs(targetMovement.X), Math.Abs(newCorrectionMovement.X)) * Math.Sign(targetMovement.X);
}
// //heading in the right direction -> use the \"normal\" movement if it's faster than correctionMovement
// //i.e. the character is close to the targetposition but the character is still running
// if (Math.Sign(targetMovement.X) == Math.Sign(newCorrectionMovement.X))
// {
// newCorrectionMovement.X = Math.Max(Math.Abs(targetMovement.X), Math.Abs(newCorrectionMovement.X)) * Math.Sign(targetMovement.X);
// }
correctionMovement = Vector2.Lerp(correctionMovement, newCorrectionMovement, 0.5f);
// correctionMovement = Vector2.Lerp(correctionMovement, newCorrectionMovement, 0.5f);
if (Math.Abs(correctionMovement.Y) < 0.1f) correctionMovement.Y = 0.0f;
}
// if (Math.Abs(correctionMovement.Y) < 0.1f) correctionMovement.Y = 0.0f;
//}
}
public virtual Vector2 EstimateCurrPosition(Vector2 prevPosition, float timePassed)
@@ -1042,15 +1056,14 @@ namespace Barotrauma
public Vector2 GetColliderBottom()
{
return collider == null ? Vector2.Zero : collider.SimPosition - Vector2.UnitY * (collider.body.height / 2 + collider.body.radius);
return collider.SimPosition - Vector2.UnitY * (collider.height / 2 + collider.radius);
}
public Limb FindLowestLimb(bool ignoreCollider)
public Limb FindLowestLimb()
{
Limb lowestLimb = null;
foreach (Limb limb in Limbs)
{
if (ignoreCollider && limb == collider) continue;
if (lowestLimb == null)
lowestLimb = limb;
else if (limb.SimPosition.Y < lowestLimb.SimPosition.Y)