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
@@ -9,6 +9,9 @@
movementlerp="0.4" movementlerp="0.4"
legtorque="15.0" legtorque="15.0"
thightorque="-5.0"> thightorque="-5.0">
<collider height="100" radius="15" mass = "70"/>
<!-- head --> <!-- head -->
<limb id = "0" radius="13" mass = "6" type="Head" attackpriority="2" impacttolerance="5.0"> <limb id = "0" radius="13" mass = "6" type="Head" attackpriority="2" impacttolerance="5.0">
@@ -76,10 +79,6 @@
<sound file ="Content/step.ogg"/> <sound file ="Content/step.ogg"/>
</limb> </limb>
<limb id = "13" height="100" radius="15" mass = "6" type="Collider">
<sprite texture="Content/Characters/Human/[GENDER]head[HEADID].png" sourcerect="1,1,1,1" depth="0.0" origin="0.5,0.5"/>
</limb>
<!-- head to body --> <!-- head to body -->
<joint limb1="0" limb1anchor="0,-7" limb2="1" limb2anchor="-1,26" lowerlimit="-90" upperlimit="45"/> <joint limb1="0" limb1anchor="0,-7" limb2="1" limb2anchor="-1,26" lowerlimit="-90" upperlimit="45"/>
<joint limb1="1" limb1anchor="0,-17" limb2="12" limb2anchor="0,7" lowerlimit="-10" upperlimit="10"/> <joint limb1="1" limb1anchor="0,-17" limb2="12" limb2anchor="0,7" lowerlimit="-10" upperlimit="10"/>
@@ -41,7 +41,7 @@ namespace Barotrauma
public Vector2 Velocity public Vector2 Velocity
{ {
get { return Character.AnimController.RefLimb.LinearVelocity; } get { return Character.AnimController.Collider.LinearVelocity; }
} }
public AiState State public AiState State
@@ -139,13 +139,12 @@ namespace Barotrauma
} }
} }
//currentPath.CheckProgress(pos, allowedDistance); var collider = character.AnimController.Collider;
var collider = character.AnimController.GetLimb(LimbType.Collider);
Vector2 colliderBottom = character.AnimController.GetColliderBottom();
if (Math.Abs(collider.SimPosition.X - currentPath.CurrentNode.SimPosition.X) < collider.body.radius*2 && Vector2 colliderBottom = character.AnimController.GetColliderBottom();
if (Math.Abs(collider.SimPosition.X - currentPath.CurrentNode.SimPosition.X) < collider.radius*2 &&
currentPath.CurrentNode.SimPosition.Y > colliderBottom.Y && currentPath.CurrentNode.SimPosition.Y > colliderBottom.Y &&
currentPath.CurrentNode.SimPosition.Y < colliderBottom.Y + collider.body.height + collider.body.radius*2) currentPath.CurrentNode.SimPosition.Y < colliderBottom.Y + collider.height + collider.radius*2)
{ {
currentPath.SkipToNextNode(); currentPath.SkipToNextNode();
} }
@@ -73,7 +73,7 @@ namespace Barotrauma
} }
else else
{ {
if (inWater || RefLimb.inWater) if (inWater)// || RefLimb.inWater)
{ {
UpdateSineAnim(deltaTime); UpdateSineAnim(deltaTime);
} }
@@ -224,25 +224,27 @@ namespace Barotrauma
void UpdateSimpleAnim() void UpdateSimpleAnim()
{ {
movement = MathUtils.SmoothStep(movement, TargetMovement*swimSpeed, 1.0f); //todo: reimplement
if (movement == Vector2.Zero) return;
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( //RefLimb.body.SmoothRotate(
(rotateTowardsMovement) ? // (rotateTowardsMovement) ?
RefLimb.body.Rotation + MathUtils.GetShortestAngle(RefLimb.body.Rotation, movementAngle) : // RefLimb.body.Rotation + MathUtils.GetShortestAngle(RefLimb.body.Rotation, movementAngle) :
HeadAngle*Dir); // HeadAngle*Dir);
RefLimb.body.LinearVelocity = movement; //collider.LinearVelocity = movement;
//RefLimb.body.SmoothRotate(0.0f); ////RefLimb.body.SmoothRotate(0.0f);
foreach (Limb l in Limbs) //foreach (Limb l in Limbs)
{ //{
if (l == RefLimb) continue; // if (l == RefLimb) continue;
l.body.SetTransform(RefLimb.SimPosition, RefLimb.Rotation); // l.body.SetTransform(RefLimb.SimPosition, RefLimb.Rotation);
} //}
} }
void UpdateWalkAnim(float deltaTime) void UpdateWalkAnim(float deltaTime)
@@ -344,7 +346,7 @@ namespace Barotrauma
if (Math.Abs(colliderPos.Y - floorY) < colliderHeight * 1.2f) 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; float walkCycleSpeed = head.LinearVelocity.X * 0.05f;
@@ -373,14 +375,14 @@ namespace Barotrauma
if (limb.type == LimbType.LeftFoot) if (limb.type == LimbType.LeftFoot)
{ {
limb.Move(footPos +new Vector2( limb.MoveToPos(footPos +new Vector2(
transformedStepSize.X + movement.X * 0.1f, transformedStepSize.X + movement.X * 0.1f,
(transformedStepSize.Y > 0.0f) ? transformedStepSize.Y : 0.0f), (transformedStepSize.Y > 0.0f) ? transformedStepSize.Y : 0.0f),
8.0f); 8.0f);
} }
else if (limb.type == LimbType.RightFoot) else if (limb.type == LimbType.RightFoot)
{ {
limb.Move(footPos +new Vector2( limb.MoveToPos(footPos +new Vector2(
-transformedStepSize.X + movement.X * 0.1f, -transformedStepSize.X + movement.X * 0.1f,
(-transformedStepSize.Y > 0.0f) ? -transformedStepSize.Y : 0.0f), (-transformedStepSize.Y > 0.0f) ? -transformedStepSize.Y : 0.0f),
8.0f); 8.0f);
@@ -63,11 +63,10 @@ namespace Barotrauma
{ {
if (character.IsDead || Frozen || character.IsUnconscious || stunTimer > 0.0f) if (character.IsDead || Frozen || character.IsUnconscious || stunTimer > 0.0f)
{ {
collider.Disabled = true; collider.PhysEnabled = false;
collider.body.PhysEnabled = false;
var lowestLimb = FindLowestLimb(true); var lowestLimb = FindLowestLimb();
collider.body.SetTransform(GetLimb(LimbType.Torso).SimPosition, 0.0f); collider.SetTransform(GetLimb(LimbType.Torso).SimPosition, 0.0f);
if (stunTimer > 0) if (stunTimer > 0)
{ {
@@ -77,7 +76,14 @@ namespace Barotrauma
return; 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; //if (inWater) stairs = null;
@@ -153,8 +159,8 @@ namespace Barotrauma
bool onStairs = stairs != null; bool onStairs = stairs != null;
stairs = null; stairs = null;
var contacts = collider.body.FarseerBody.ContactList; var contacts = collider.FarseerBody.ContactList;
while (collider.body.PhysEnabled && contacts != null && contacts.Contact != null) while (collider.FarseerBody.Enabled && contacts != null && contacts.Contact != null)
{ {
if (contacts.Contact.Enabled && contacts.Contact.IsTouching) if (contacts.Contact.Enabled && contacts.Contact.IsTouching)
{ {
@@ -219,18 +225,13 @@ namespace Barotrauma
onFloorTimer -= deltaTime; 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); var lowestLimb = FindLowestLimb();
collider.body.SetTransform(lowestLimb.SimPosition + Vector2.UnitY * (collider.body.radius + collider.body.height / 2), 0.0f); collider.SetTransform(lowestLimb.SimPosition + Vector2.UnitY * (collider.radius + collider.height / 2), 0.0f);
collider.Disabled = false; collider.FarseerBody.Enabled = true;
} }
if (character.LockHands) if (character.LockHands)
@@ -274,12 +275,8 @@ namespace Barotrauma
UpdateStandingSimple(); UpdateStandingSimple();
return; return;
} }
collider.body.PhysEnabled = true;
collider.body.Enabled = true;
switch (Anim) switch (Anim)
{ {
case Animation.Climbing: case Animation.Climbing:
@@ -324,7 +321,6 @@ namespace Barotrauma
foreach (Limb limb in Limbs) foreach (Limb limb in Limbs)
{ {
if (limb == collider) continue;
limb.Disabled = false; limb.Disabled = false;
} }
@@ -430,7 +426,7 @@ namespace Barotrauma
if (onGround) if (onGround)
{ {
collider.body.LinearVelocity = new Vector2( collider.LinearVelocity = new Vector2(
movement.X * 1.5f, movement.X * 1.5f,
collider.LinearVelocity.Y > 0.0f ? collider.LinearVelocity.Y * 0.5f : collider.LinearVelocity.Y); collider.LinearVelocity.Y > 0.0f ? collider.LinearVelocity.Y * 0.5f : collider.LinearVelocity.Y);
} }
@@ -483,7 +479,6 @@ namespace Barotrauma
foreach (Limb limb in Limbs) foreach (Limb limb in Limbs)
{ {
if (limb == collider) continue;
MoveLimb(limb, limb.SimPosition+move, 15.0f, true); MoveLimb(limb, limb.SimPosition+move, 15.0f, true);
} }
@@ -635,9 +630,8 @@ namespace Barotrauma
Limb head = GetLimb(LimbType.Head); Limb head = GetLimb(LimbType.Head);
Limb torso = GetLimb(LimbType.Torso); Limb torso = GetLimb(LimbType.Torso);
collider.body.PhysEnabled = false; collider.FarseerBody.Enabled = false;
collider.Disabled = true; collider.SetTransform(torso.SimPosition, 0.0f);
collider.body.SetTransform(torso.SimPosition, 0.0f);
if (currentHull != null && (currentHull.Rect.Y - currentHull.Surface > 50.0f) && !head.inWater) 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(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(waist, new Vector2(ladderSimPos.X - 0.35f * Dir, collider.SimPosition.Y+0.4f), 10.5f);
collider.MoveToPos(new Vector2(ladderSimPos.X - 0.2f * Dir, collider.SimPosition.Y), 10.5f);
MoveLimb(collider, new Vector2(ladderSimPos.X - 0.2f * Dir, collider.SimPosition.Y), 10.5f);
Vector2 handPos = new Vector2( Vector2 handPos = new Vector2(
ladderSimPos.X, ladderSimPos.X,
collider.SimPosition.Y + 0.6f + movement.Y * 0.1f - ladderSimPos.Y); collider.SimPosition.Y + 0.6f + movement.Y * 0.1f - ladderSimPos.Y);
@@ -901,7 +894,6 @@ namespace Barotrauma
leftLeg.body.ApplyTorque(Dir * -8.0f); leftLeg.body.ApplyTorque(Dir * -8.0f);
rightLeg.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; float movementFactor = (handPos.Y / stepHeight) * (float)Math.PI;
movementFactor = 0.8f + (float)Math.Abs(Math.Sin(movementFactor)); 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; Vector2 climbForce = new Vector2(0.0f, movement.Y + 0.3f) * movementFactor;
//if (climbForce.Y > 0.5f) climbForce.Y = Math.Max(climbForce.Y, 1.3f); //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); head.body.SmoothRotate(0.0f);
if (!character.SelectedConstruction.Prefab.Triggers.Any()) if (!character.SelectedConstruction.Prefab.Triggers.Any())
@@ -1313,7 +1306,7 @@ namespace Barotrauma
float angle = flipAngle ? -limb.body.Rotation : limb.body.Rotation; float angle = flipAngle ? -limb.body.Rotation : limb.body.Rotation;
if (wrapAngle) angle = MathUtils.WrapAnglePi(angle); if (wrapAngle) angle = MathUtils.WrapAnglePi(angle);
TrySetLimbPosition(limb, RefLimb.SimPosition, position); TrySetLimbPosition(limb, collider.SimPosition, position);
limb.body.SetTransform(limb.body.SimPosition, angle); limb.body.SetTransform(limb.body.SimPosition, angle);
} }
+185 -172
View File
@@ -20,8 +20,23 @@ namespace Barotrauma
public Limb[] Limbs; public Limb[] Limbs;
private bool isFrozen = false; private bool frozen;
public bool Frozen = false; 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; private Dictionary<LimbType, Limb> limbDictionary;
public RevoluteJoint[] limbJoints; public RevoluteJoint[] limbJoints;
@@ -54,22 +69,20 @@ namespace Barotrauma
protected bool inWater, headInWater; protected bool inWater, headInWater;
public bool onGround; public bool onGround;
private bool ignorePlatforms; private bool ignorePlatforms;
protected Limb refLimb;
protected Structure stairs; protected Structure stairs;
protected Direction dir; protected Direction dir;
public Direction TargetDir; public Direction TargetDir;
protected Limb collider; protected PhysicsBody collider;
public Limb RefLimb public PhysicsBody Collider
{ {
get get
{ {
return refLimb; return collider;
} }
} }
@@ -84,26 +97,39 @@ namespace Barotrauma
private set; private set;
} }
public Vector2 WorldPosition
{
get
{
return character.Submarine == null ?
ConvertUnits.ToDisplayUnits(collider.SimPosition) :
ConvertUnits.ToDisplayUnits(collider.SimPosition) + character.Submarine.Position;
}
}
public bool SimplePhysicsEnabled public bool SimplePhysicsEnabled
{ {
get { return simplePhysicsEnabled; } get { return simplePhysicsEnabled; }
set set
{ {
if (value == simplePhysicsEnabled) return; //TODO: reimplement
return;
//if (value == simplePhysicsEnabled) return;
simplePhysicsEnabled = value; //simplePhysicsEnabled = value;
foreach (Limb limb in Limbs) //foreach (Limb limb in Limbs)
{ //{
limb.body.Enabled = !simplePhysicsEnabled; // limb.body.Enabled = !simplePhysicsEnabled;
} //}
foreach (RevoluteJoint joint in limbJoints) //foreach (RevoluteJoint joint in limbJoints)
{ //{
joint.Enabled = !simplePhysicsEnabled; // joint.Enabled = !simplePhysicsEnabled;
} //}
refLimb.body.Enabled = true; //refLimb.body.Enabled = true;
} }
} }
@@ -166,10 +192,12 @@ namespace Barotrauma
if (value == currentHull) return; if (value == currentHull) return;
currentHull = value; currentHull = value;
Submarine currSubmarine = currentHull == null ? null : currentHull.Submarine;
foreach (Limb limb in Limbs) 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": case "joint":
AddJoint(subElement, scale); AddJoint(subElement, scale);
break;
case "collider":
collider = new PhysicsBody(subElement, scale);
collider.FarseerBody.FixedRotation = true;
break; break;
} }
} }
refLimb = GetLimb(LimbType.Torso); if (collider == null)
if (refLimb == null) refLimb = GetLimb(LimbType.Head); {
if (refLimb == null) DebugConsole.ThrowError("Character \"" + character + "\" doesn't have a head or torso!"); 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(); UpdateCollisionCategories();
foreach (var joint in limbJoints) foreach (var joint in limbJoints)
{ {
joint.BodyB.SetTransform( joint.BodyB.SetTransform(
joint.BodyA.Position + (joint.LocalAnchorA - joint.LocalAnchorB)*0.1f, joint.BodyA.Position + (joint.LocalAnchorA - joint.LocalAnchorB)*0.1f,
(joint.LowerLimit + joint.UpperLimit) / 2.0f); (joint.LowerLimit + joint.UpperLimit) / 2.0f);
@@ -272,13 +308,6 @@ namespace Barotrauma
{ {
limb.sprite.Depth = startDepth + limb.sprite.Depth * 0.0001f; 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) public void AddJoint(XElement subElement, float scale = 1.0f)
@@ -443,33 +472,35 @@ namespace Barotrauma
// avgVelocity += limb.LinearVelocity; // avgVelocity += limb.LinearVelocity;
//} //}
Limb limb = (Limb)f1.Body.UserData; Vector2 velocity = f1.Body.LinearVelocity;
Vector2 velocity = limb.LinearVelocity;
if (character.Submarine == null && f2.Body.UserData is Submarine) velocity -= ((Submarine)f2.Body.UserData).Velocity; if (character.Submarine == null && f2.Body.UserData is Submarine) velocity -= ((Submarine)f2.Body.UserData).Velocity;
float impact = Vector2.Dot(velocity, -normal); float impact = Vector2.Dot(velocity, -normal);
float volume = stairs == null ? impact / 5.0f : impact; if (f1.Body.UserData is Limb)
volume = Math.Min(impact, 1.0f);
if (impact > 0.5f && limb.HitSound != null && limb.soundTimer <= 0.0f)
{ {
limb.soundTimer = Limb.SoundInterval; Limb limb = (Limb)f1.Body.UserData;
limb.HitSound.Play(volume, impact * 250.0f, limb.WorldPosition);
}
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) if (!character.IsNetworkPlayer || GameMain.Server != null)
{ {
character.AddDamage(CauseOfDeath.Damage, impact - limb.impactTolerance * 0.1f, null); character.AddDamage(CauseOfDeath.Damage, impact - 8.0f, null);
strongestImpact = Math.Max(strongestImpact, impact - limb.impactTolerance); 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; if (Character.Controlled == character) GameMain.GameScreen.Cam.Shake = strongestImpact;
} }
@@ -478,6 +509,8 @@ namespace Barotrauma
public virtual void Draw(SpriteBatch spriteBatch) public virtual void Draw(SpriteBatch spriteBatch)
{ {
if (simplePhysicsEnabled) return; if (simplePhysicsEnabled) return;
collider.UpdateDrawPosition();
foreach (Limb limb in Limbs) foreach (Limb limb in Limbs)
{ {
@@ -508,8 +541,14 @@ namespace Barotrauma
//GUI.DrawLine(spriteBatch, pos, pos2, Color.Green); //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) foreach (RevoluteJoint joint in limbJoints)
{ {
Vector2 pos = ConvertUnits.ToDisplayUnits(joint.WorldAnchorA); Vector2 pos = ConvertUnits.ToDisplayUnits(joint.WorldAnchorA);
@@ -528,13 +567,16 @@ namespace Barotrauma
pos.Y = -pos.Y; 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.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) 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; return centerOfMass;
} }
/// <summary>
///
/// </summary>
/// <param name="pullFromCenter">if false, force is applied to the position of pullJoint</param> /// <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) 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() 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; if (Limbs[i] == null || Limbs[i].pullJoint == null) continue;
Limbs[i].pullJoint.Enabled = false; Limbs[i].pullJoint.Enabled = false;
@@ -622,7 +660,7 @@ namespace Barotrauma
return; return;
} }
Vector2 findPos = worldPosition==null ? refLimb.WorldPosition : (Vector2)worldPosition; Vector2 findPos = worldPosition==null ? this.WorldPosition : (Vector2)worldPosition;
Hull newHull = Hull.FindHull(findPos, currentHull); Hull newHull = Hull.FindHull(findPos, currentHull);
@@ -674,7 +712,6 @@ namespace Barotrauma
while (ce != null && ce.Contact != null) while (ce != null && ce.Contact != null)
{ {
ce.Contact.Enabled = false; ce.Contact.Enabled = false;
ce = ce.Next; ce = ce.Next;
} }
} }
@@ -687,7 +724,7 @@ namespace Barotrauma
//character.Stun = 0.1f; //character.Stun = 0.1f;
character.DisableImpactDamageTimer = 0.25f; character.DisableImpactDamageTimer = 0.25f;
SetPosition(refLimb.SimPosition + moveAmount); SetPosition(collider.SimPosition + moveAmount);
character.CursorPosition += moveAmount; character.CursorPosition += moveAmount;
} }
@@ -701,6 +738,8 @@ namespace Barotrauma
wall | Physics.CollisionProjectile | Physics.CollisionStairs wall | Physics.CollisionProjectile | Physics.CollisionStairs
: wall | Physics.CollisionProjectile | Physics.CollisionPlatform | Physics.CollisionStairs; : wall | Physics.CollisionProjectile | Physics.CollisionPlatform | Physics.CollisionStairs;
collider.CollidesWith = collisionCategory;
foreach (Limb limb in Limbs) foreach (Limb limb in Limbs)
{ {
if (limb.ignoreCollisions) continue; if (limb.ignoreCollisions) continue;
@@ -720,26 +759,7 @@ namespace Barotrauma
{ {
if (!character.Enabled) return; if (!character.Enabled) return;
if (Frozen) if (Frozen) return;
{
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;
}
UpdateNetPlayerPosition(); UpdateNetPlayerPosition();
@@ -845,22 +865,16 @@ namespace Barotrauma
public void SetPosition(Vector2 simPosition, bool lerp = false) 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) foreach (Limb limb in Limbs)
{ {
if (limb == refLimb) //check visibility from the new position of the collider to the new position of this limb
{ Vector2 movePos = limb.SimPosition + moveAmount;
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);
}
TrySetLimbPosition(limb, simPosition, movePos, lerp);
} }
} }
@@ -899,110 +913,110 @@ namespace Barotrauma
} }
} }
public void SetRotation(float rotation) //public void SetRotation(float rotation)
{ //{
float rotateAmount = rotation - refLimb.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) // foreach (Limb limb in Limbs)
{ // {
if (limb == refLimb) continue; // if (limb == refLimb) continue;
Vector2 newPos = limb.SimPosition - refLimb.SimPosition; // Vector2 newPos = limb.SimPosition - refLimb.SimPosition;
newPos = Vector2.Transform(newPos, rotationMatrix); // newPos = Vector2.Transform(newPos, rotationMatrix);
TrySetLimbPosition(limb, refLimb.SimPosition, refLimb.SimPosition + newPos); // TrySetLimbPosition(limb, refLimb.SimPosition, refLimb.SimPosition + newPos);
limb.body.SetTransform(limb.SimPosition, limb.Rotation + rotateAmount); // limb.body.SetTransform(limb.SimPosition, limb.Rotation + rotateAmount);
} // }
} //}
private void UpdateNetPlayerPosition() private void UpdateNetPlayerPosition()
{ {
if (refLimb.body.TargetPosition == Vector2.Zero) //if (refLimb.body.TargetPosition == Vector2.Zero)
{ //{
correctionMovement = Vector2.Zero; // correctionMovement = Vector2.Zero;
return; // return;
} //}
//if the limb is closer than alloweddistance, just ignore the difference ////if the limb is closer than alloweddistance, just ignore the difference
float allowedDistance = NetConfig.AllowedRagdollDistance * ((inWater) ? 2.0f : 1.0f); //float allowedDistance = NetConfig.AllowedRagdollDistance * ((inWater) ? 2.0f : 1.0f);
if (currentHull == null) //if (currentHull == null)
{ //{
var overLappingHull = Hull.FindHull(ConvertUnits.ToDisplayUnits(refLimb.body.TargetPosition), null, true); // var overLappingHull = Hull.FindHull(ConvertUnits.ToDisplayUnits(refLimb.body.TargetPosition), null, true);
if (overLappingHull != null) // if (overLappingHull != null)
{ // {
Submarine.PickBody(refLimb.SimPosition, refLimb.body.TargetPosition, null, Physics.CollisionWall); // 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 ////if the limb is further away than resetdistance, all limbs are immediately snapped to their targetpositions
bool resetAll = dist > NetConfig.ResetRagdollDistance; //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) //if (diff == Vector2.Zero || diff.Length() < allowedDistance)
{ //{
refLimb.body.TargetPosition = Vector2.Zero; // refLimb.body.TargetPosition = Vector2.Zero;
foreach (Limb limb in Limbs) // foreach (Limb limb in Limbs)
{ // {
limb.body.TargetPosition = Vector2.Zero; // limb.body.TargetPosition = Vector2.Zero;
} // }
correctionMovement = Vector2.Zero; // correctionMovement = Vector2.Zero;
return; // return;
} //}
if (resetAll) //if (resetAll)
{ //{
System.Diagnostics.Debug.WriteLine("reset ragdoll limb positions"); // 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 (inWater)
{ //{
if (targetMovement.LengthSquared() > 0.01f) // if (targetMovement.LengthSquared() > 0.01f)
{ // {
correctionMovement = // correctionMovement =
Vector2.Lerp(targetMovement, Vector2.Normalize(diff) * MathHelper.Clamp(dist * 5.0f, 0.1f, 5.0f), 0.2f); // Vector2.Lerp(targetMovement, Vector2.Normalize(diff) * MathHelper.Clamp(dist * 5.0f, 0.1f, 5.0f), 0.2f);
} // }
else // else
{ // {
refLimb.body.LinearVelocity = Vector2.Lerp( // refLimb.body.LinearVelocity = Vector2.Lerp(
refLimb.LinearVelocity, // refLimb.LinearVelocity,
Vector2.Normalize(diff) * MathHelper.Clamp(dist, 0.0f, 5.0f), // Vector2.Normalize(diff) * MathHelper.Clamp(dist, 0.0f, 5.0f),
0.2f); // 0.2f);
} // }
} //}
else //else
{ //{
//clamp the magnitude of the correction movement between 0.5f - 5.0f // //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); // 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 // //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 // //i.e. the character is close to the targetposition but the character is still running
if (Math.Sign(targetMovement.X) == Math.Sign(newCorrectionMovement.X)) // 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); // 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) public virtual Vector2 EstimateCurrPosition(Vector2 prevPosition, float timePassed)
@@ -1042,15 +1056,14 @@ namespace Barotrauma
public Vector2 GetColliderBottom() 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; Limb lowestLimb = null;
foreach (Limb limb in Limbs) foreach (Limb limb in Limbs)
{ {
if (ignoreCollider && limb == collider) continue;
if (lowestLimb == null) if (lowestLimb == null)
lowestLimb = limb; lowestLimb = limb;
else if (limb.SimPosition.Y < lowestLimb.SimPosition.Y) else if (limb.SimPosition.Y < lowestLimb.SimPosition.Y)
+8 -7
View File
@@ -428,17 +428,17 @@ namespace Barotrauma
public override Vector2 SimPosition public override Vector2 SimPosition
{ {
get { return AnimController.RefLimb.SimPosition; } get { return AnimController.Collider.SimPosition; }
} }
public override Vector2 Position public override Vector2 Position
{ {
get { return AnimController.RefLimb.Position; } get { return ConvertUnits.ToDisplayUnits(SimPosition); }
} }
public override Vector2 DrawPosition public override Vector2 DrawPosition
{ {
get { return AnimController.RefLimb.body.DrawPosition; } get { return AnimController.Collider.DrawPosition; }
} }
public delegate void OnDeathHandler(Character character, CauseOfDeath causeOfDeath); public delegate void OnDeathHandler(Character character, CauseOfDeath causeOfDeath);
@@ -560,12 +560,12 @@ namespace Barotrauma
//FishAnimController fishAnim = (FishAnimController)animController; //FishAnimController fishAnim = (FishAnimController)animController;
} }
AnimController.SetPosition(ConvertUnits.ToSimUnits(position));
foreach (Limb limb in AnimController.Limbs) foreach (Limb limb in AnimController.Limbs)
{ {
limb.body.SetTransform(ConvertUnits.ToSimUnits(position)+limb.SimPosition, 0.0f); limb.body.SetTransform(ConvertUnits.ToSimUnits(position)+limb.SimPosition, 0.0f);
//limb.prevPosition = ConvertUnits.ToDisplayUnits(position);
} }
maxHealth = ToolBox.GetAttributeFloat(doc.Root, "health", 100.0f); maxHealth = ToolBox.GetAttributeFloat(doc.Root, "health", 100.0f);
health = maxHealth; health = maxHealth;
@@ -1197,6 +1197,7 @@ namespace Barotrauma
foreach (Character c in CharacterList) foreach (Character c in CharacterList)
{ {
if (!c.Enabled) continue; if (!c.Enabled) continue;
c.AnimController.UpdateAnim(deltaTime); c.AnimController.UpdateAnim(deltaTime);
} }
} }
@@ -1412,7 +1413,7 @@ namespace Barotrauma
aiTarget.SightRange = 0.0f; aiTarget.SightRange = 0.0f;
aiTarget.SightRange = Mass*10.0f + AnimController.RefLimb.LinearVelocity.Length()*500.0f; aiTarget.SightRange = Mass*10.0f + AnimController.Collider.LinearVelocity.Length()*500.0f;
} }
public void ShowSpeechBubble(float duration, Color color) public void ShowSpeechBubble(float duration, Color color)
@@ -1622,7 +1623,7 @@ namespace Barotrauma
// limb.Damage = 100.0f; // limb.Damage = 100.0f;
} }
SoundPlayer.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.RefLimb.body); SoundPlayer.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.Collider);
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
+5 -47
View File
@@ -16,8 +16,7 @@ namespace Barotrauma
public enum LimbType public enum LimbType
{ {
None, LeftHand, RightHand, LeftArm, RightArm, None, LeftHand, RightHand, LeftArm, RightArm,
LeftLeg, RightLeg, LeftFoot, RightFoot, Head, Torso, Tail, Legs, RightThigh, LeftThigh, Waist, LeftLeg, RightLeg, LeftFoot, RightFoot, Head, Torso, Tail, Legs, RightThigh, LeftThigh, Waist
Collider
}; };
class Limb class Limb
@@ -29,7 +28,6 @@ namespace Barotrauma
//the physics body of the limb //the physics body of the limb
public PhysicsBody body; public PhysicsBody body;
private Texture2D bodyShapeTexture;
private readonly int refJointIndex; private readonly int refJointIndex;
@@ -74,11 +72,6 @@ namespace Barotrauma
private List<WearableSprite> wearingItems; private List<WearableSprite> wearingItems;
private Vector2 animTargetPos; private Vector2 animTargetPos;
public Texture2D BodyShapeTexture
{
get { return bodyShapeTexture; }
}
public bool DoesFlip public bool DoesFlip
{ {
@@ -335,7 +328,7 @@ namespace Barotrauma
} }
} }
public void Move(Vector2 pos, float amount, bool pullFromCenter=false) public void MoveToPos(Vector2 pos, float force, bool pullFromCenter=false)
{ {
Vector2 pullPos = body.SimPosition; Vector2 pullPos = body.SimPosition;
if (pullJoint!=null && !pullFromCenter) if (pullJoint!=null && !pullFromCenter)
@@ -345,10 +338,7 @@ namespace Barotrauma
animTargetPos = pos; animTargetPos = pos;
Vector2 vel = body.LinearVelocity; body.MoveToPos(pos, force, pullPos);
Vector2 deltaPos = pos - pullPos;
deltaPos *= amount;
body.ApplyLinearImpulse((deltaPos - vel * 0.5f) * body.Mass, pullPos);
} }
public AttackResult AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, bool playSound) public AttackResult AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, bool playSound)
@@ -446,7 +436,7 @@ namespace Barotrauma
{ {
//DebugConsole.ThrowError("CHARACTER EXPLODED"); //DebugConsole.ThrowError("CHARACTER EXPLODED");
body.ResetDynamics(); body.ResetDynamics();
body.SetTransform(character.AnimController.RefLimb.SimPosition, 0.0f); body.SetTransform(character.SimPosition, 0.0f);
} }
if (inWater) if (inWater)
@@ -586,34 +576,7 @@ namespace Barotrauma
GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)-pos.Y, 5, 5), Color.Red, true); GUI.DrawRectangle(spriteBatch, new Rectangle((int)pos.X, (int)-pos.Y, 5, 5), Color.Red, true);
} }
if (bodyShapeTexture == null)
{
switch (body.BodyShape)
{
case PhysicsBody.Shape.Rectangle:
bodyShapeTexture = GUI.CreateRectangle(
(int)ConvertUnits.ToDisplayUnits(body.width),
(int)ConvertUnits.ToDisplayUnits(body.height));
break;
case PhysicsBody.Shape.Capsule:
bodyShapeTexture = GUI.CreateCapsule(
(int)ConvertUnits.ToDisplayUnits(body.radius),
(int)ConvertUnits.ToDisplayUnits(body.height));
break;
case PhysicsBody.Shape.Circle:
bodyShapeTexture = GUI.CreateCircle((int)ConvertUnits.ToDisplayUnits(body.radius));
break;
}
}
spriteBatch.Draw(
bodyShapeTexture,
new Vector2(body.DrawPosition.X, -body.DrawPosition.Y),
null,
character.Submarine!=null ? Color.White : Color.Cyan,
-body.DrawRotation,
new Vector2(bodyShapeTexture.Width / 2, bodyShapeTexture.Height / 2), 1.0f, SpriteEffects.None, 0.0f);
} }
@@ -625,11 +588,6 @@ namespace Barotrauma
body.Remove(); body.Remove();
if (bodyShapeTexture != null)
{
bodyShapeTexture.Dispose();
}
if (hitSound != null) hitSound.Remove(); if (hitSound != null) hitSound.Remove();
} }
} }
@@ -92,7 +92,7 @@ namespace Barotrauma.Items.Components
if (userPos != 0.0f) if (userPos != 0.0f)
{ {
float torsoX = ConvertUnits.ToDisplayUnits(character.AnimController.RefLimb.SimPosition.X); float torsoX = character.Position.X;
Vector2 diff = new Vector2(item.Rect.X + UserPos - torsoX, 0.0f); Vector2 diff = new Vector2(item.Rect.X + UserPos - torsoX, 0.0f);
+2 -2
View File
@@ -495,8 +495,8 @@ namespace Barotrauma
FixedArray2<Vector2> points; FixedArray2<Vector2> points;
contact.GetWorldManifold(out normal2, out points); contact.GetWorldManifold(out normal2, out points);
Vector2 normalizedVel = limb.character.AnimController.RefLimb.LinearVelocity == Vector2.Zero ? Vector2 normalizedVel = limb.character.AnimController.Collider.LinearVelocity == Vector2.Zero ?
Vector2.Zero : Vector2.Normalize(limb.character.AnimController.RefLimb.LinearVelocity); Vector2.Zero : Vector2.Normalize(limb.character.AnimController.Collider.LinearVelocity);
Vector2 targetPos = ConvertUnits.ToDisplayUnits(points[0] - normal2); Vector2 targetPos = ConvertUnits.ToDisplayUnits(points[0] - normal2);
+56 -2
View File
@@ -201,6 +201,12 @@ namespace Barotrauma
set { body.CollidesWith = value; } set { body.CollidesWith = value; }
} }
private Texture2D bodyShapeTexture;
public Texture2D BodyShapeTexture
{
get { return bodyShapeTexture; }
}
public PhysicsBody(XElement element, float scale = 1.0f) public PhysicsBody(XElement element, float scale = 1.0f)
: this(element, Vector2.Zero, scale) : this(element, Vector2.Zero, scale)
{ {
@@ -336,6 +342,15 @@ namespace Barotrauma
targetPosition = Vector2.Zero; targetPosition = Vector2.Zero;
} }
public void MoveToPos(Vector2 pos, float force, Vector2? pullPos = null)
{
if (pullPos==null) pullPos = body.Position;
Vector2 vel = body.LinearVelocity;
Vector2 deltaPos = pos - (Vector2)pullPos;
deltaPos *= force;
body.ApplyLinearImpulse((deltaPos - vel * 0.5f) * body.Mass, (Vector2)pullPos);
}
public void UpdateDrawPosition() public void UpdateDrawPosition()
{ {
@@ -370,10 +385,43 @@ namespace Barotrauma
color = Color.Blue; color = Color.Blue;
} }
sprite.Draw(spriteBatch, new Vector2(DrawPosition.X, -DrawPosition.Y), color, -drawRotation, scale, spriteEffect, depth); sprite.Draw(spriteBatch, new Vector2(DrawPosition.X, -DrawPosition.Y), color, -drawRotation, scale, spriteEffect, depth);
} }
public void DebugDraw(SpriteBatch spriteBatch, Color color)
{
if (bodyShapeTexture == null)
{
switch (BodyShape)
{
case PhysicsBody.Shape.Rectangle:
bodyShapeTexture = GUI.CreateRectangle(
(int)ConvertUnits.ToDisplayUnits(width),
(int)ConvertUnits.ToDisplayUnits(height));
break;
case PhysicsBody.Shape.Capsule:
bodyShapeTexture = GUI.CreateCapsule(
(int)ConvertUnits.ToDisplayUnits(radius),
(int)ConvertUnits.ToDisplayUnits(height));
break;
case PhysicsBody.Shape.Circle:
bodyShapeTexture = GUI.CreateCircle((int)ConvertUnits.ToDisplayUnits(radius));
break;
}
}
spriteBatch.Draw(
bodyShapeTexture,
new Vector2(DrawPosition.X, -DrawPosition.Y),
null,
color,
-DrawRotation,
new Vector2(bodyShapeTexture.Width / 2, bodyShapeTexture.Height / 2),
1.0f, SpriteEffects.None, 0.0f);
}
/// <summary> /// <summary>
/// rotate the body towards the target rotation in the "shortest direction" /// rotate the body towards the target rotation in the "shortest direction"
/// </summary> /// </summary>
@@ -399,6 +447,12 @@ namespace Barotrauma
{ {
list.Remove(this); list.Remove(this);
GameMain.World.RemoveBody(body); GameMain.World.RemoveBody(body);
if (bodyShapeTexture != null)
{
bodyShapeTexture.Dispose();
bodyShapeTexture = null;
}
} }
} }
@@ -173,12 +173,12 @@ namespace Barotrauma
DrawJoints(spriteBatch, limb, limbBodyPos); DrawJoints(spriteBatch, limb, limbBodyPos);
if (limb.BodyShapeTexture == null) continue; //if (limb.BodyShapeTexture == null) continue;
spriteBatch.Draw(limb.BodyShapeTexture, limbBodyPos, //spriteBatch.Draw(limb.BodyShapeTexture, limbBodyPos,
null, Color.White, 0.0f, // null, Color.White, 0.0f,
new Vector2(limb.BodyShapeTexture.Width, limb.BodyShapeTexture.Height) / 2, // new Vector2(limb.BodyShapeTexture.Width, limb.BodyShapeTexture.Height) / 2,
1.0f, SpriteEffects.None, 0.0f); // 1.0f, SpriteEffects.None, 0.0f);
GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitY * 5.0f, limbBodyPos - Vector2.UnitY * 5.0f, Color.White); GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitY * 5.0f, limbBodyPos - Vector2.UnitY * 5.0f, Color.White);
GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitX * 5.0f, limbBodyPos - Vector2.UnitX * 5.0f, Color.White); GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitX * 5.0f, limbBodyPos - Vector2.UnitX * 5.0f, Color.White);