Changed colliders from limbs to normal physics bodies, removed RefLimb
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
movementlerp="0.4"
|
||||
legtorque="15.0"
|
||||
thightorque="-5.0">
|
||||
|
||||
|
||||
<collider height="100" radius="15" mass = "70"/>
|
||||
|
||||
<!-- head -->
|
||||
<limb id = "0" radius="13" mass = "6" type="Head" attackpriority="2" impacttolerance="5.0">
|
||||
@@ -76,10 +79,6 @@
|
||||
<sound file ="Content/step.ogg"/>
|
||||
</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 -->
|
||||
<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"/>
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Barotrauma
|
||||
|
||||
public Vector2 Velocity
|
||||
{
|
||||
get { return Character.AnimController.RefLimb.LinearVelocity; }
|
||||
get { return Character.AnimController.Collider.LinearVelocity; }
|
||||
}
|
||||
|
||||
public AiState State
|
||||
|
||||
@@ -139,13 +139,12 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
//currentPath.CheckProgress(pos, allowedDistance);
|
||||
var collider = character.AnimController.GetLimb(LimbType.Collider);
|
||||
Vector2 colliderBottom = character.AnimController.GetColliderBottom();
|
||||
var collider = character.AnimController.Collider;
|
||||
|
||||
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 + collider.body.height + collider.body.radius*2)
|
||||
currentPath.CurrentNode.SimPosition.Y < colliderBottom.Y + collider.height + collider.radius*2)
|
||||
{
|
||||
currentPath.SkipToNextNode();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -428,17 +428,17 @@ namespace Barotrauma
|
||||
|
||||
public override Vector2 SimPosition
|
||||
{
|
||||
get { return AnimController.RefLimb.SimPosition; }
|
||||
get { return AnimController.Collider.SimPosition; }
|
||||
}
|
||||
|
||||
public override Vector2 Position
|
||||
{
|
||||
get { return AnimController.RefLimb.Position; }
|
||||
get { return ConvertUnits.ToDisplayUnits(SimPosition); }
|
||||
}
|
||||
|
||||
public override Vector2 DrawPosition
|
||||
{
|
||||
get { return AnimController.RefLimb.body.DrawPosition; }
|
||||
get { return AnimController.Collider.DrawPosition; }
|
||||
}
|
||||
|
||||
public delegate void OnDeathHandler(Character character, CauseOfDeath causeOfDeath);
|
||||
@@ -560,12 +560,12 @@ namespace Barotrauma
|
||||
//FishAnimController fishAnim = (FishAnimController)animController;
|
||||
}
|
||||
|
||||
AnimController.SetPosition(ConvertUnits.ToSimUnits(position));
|
||||
foreach (Limb limb in AnimController.Limbs)
|
||||
{
|
||||
limb.body.SetTransform(ConvertUnits.ToSimUnits(position)+limb.SimPosition, 0.0f);
|
||||
//limb.prevPosition = ConvertUnits.ToDisplayUnits(position);
|
||||
}
|
||||
|
||||
|
||||
maxHealth = ToolBox.GetAttributeFloat(doc.Root, "health", 100.0f);
|
||||
health = maxHealth;
|
||||
|
||||
@@ -1197,6 +1197,7 @@ namespace Barotrauma
|
||||
foreach (Character c in CharacterList)
|
||||
{
|
||||
if (!c.Enabled) continue;
|
||||
|
||||
c.AnimController.UpdateAnim(deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -1412,7 +1413,7 @@ namespace Barotrauma
|
||||
|
||||
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)
|
||||
@@ -1622,7 +1623,7 @@ namespace Barotrauma
|
||||
// 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++)
|
||||
{
|
||||
|
||||
@@ -16,8 +16,7 @@ namespace Barotrauma
|
||||
public enum LimbType
|
||||
{
|
||||
None, LeftHand, RightHand, LeftArm, RightArm,
|
||||
LeftLeg, RightLeg, LeftFoot, RightFoot, Head, Torso, Tail, Legs, RightThigh, LeftThigh, Waist,
|
||||
Collider
|
||||
LeftLeg, RightLeg, LeftFoot, RightFoot, Head, Torso, Tail, Legs, RightThigh, LeftThigh, Waist
|
||||
};
|
||||
|
||||
class Limb
|
||||
@@ -29,7 +28,6 @@ namespace Barotrauma
|
||||
|
||||
//the physics body of the limb
|
||||
public PhysicsBody body;
|
||||
private Texture2D bodyShapeTexture;
|
||||
|
||||
private readonly int refJointIndex;
|
||||
|
||||
@@ -74,11 +72,6 @@ namespace Barotrauma
|
||||
private List<WearableSprite> wearingItems;
|
||||
|
||||
private Vector2 animTargetPos;
|
||||
|
||||
public Texture2D BodyShapeTexture
|
||||
{
|
||||
get { return bodyShapeTexture; }
|
||||
}
|
||||
|
||||
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;
|
||||
if (pullJoint!=null && !pullFromCenter)
|
||||
@@ -345,10 +338,7 @@ namespace Barotrauma
|
||||
|
||||
animTargetPos = pos;
|
||||
|
||||
Vector2 vel = body.LinearVelocity;
|
||||
Vector2 deltaPos = pos - pullPos;
|
||||
deltaPos *= amount;
|
||||
body.ApplyLinearImpulse((deltaPos - vel * 0.5f) * body.Mass, pullPos);
|
||||
body.MoveToPos(pos, force, pullPos);
|
||||
}
|
||||
|
||||
public AttackResult AddDamage(Vector2 position, DamageType damageType, float amount, float bleedingAmount, bool playSound)
|
||||
@@ -446,7 +436,7 @@ namespace Barotrauma
|
||||
{
|
||||
//DebugConsole.ThrowError("CHARACTER EXPLODED");
|
||||
body.ResetDynamics();
|
||||
body.SetTransform(character.AnimController.RefLimb.SimPosition, 0.0f);
|
||||
body.SetTransform(character.SimPosition, 0.0f);
|
||||
}
|
||||
|
||||
if (inWater)
|
||||
@@ -586,34 +576,7 @@ namespace Barotrauma
|
||||
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();
|
||||
|
||||
if (bodyShapeTexture != null)
|
||||
{
|
||||
bodyShapeTexture.Dispose();
|
||||
}
|
||||
|
||||
if (hitSound != null) hitSound.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -495,8 +495,8 @@ namespace Barotrauma
|
||||
FixedArray2<Vector2> points;
|
||||
contact.GetWorldManifold(out normal2, out points);
|
||||
|
||||
Vector2 normalizedVel = limb.character.AnimController.RefLimb.LinearVelocity == Vector2.Zero ?
|
||||
Vector2.Zero : Vector2.Normalize(limb.character.AnimController.RefLimb.LinearVelocity);
|
||||
Vector2 normalizedVel = limb.character.AnimController.Collider.LinearVelocity == Vector2.Zero ?
|
||||
Vector2.Zero : Vector2.Normalize(limb.character.AnimController.Collider.LinearVelocity);
|
||||
|
||||
Vector2 targetPos = ConvertUnits.ToDisplayUnits(points[0] - normal2);
|
||||
|
||||
|
||||
@@ -201,6 +201,12 @@ namespace Barotrauma
|
||||
set { body.CollidesWith = value; }
|
||||
}
|
||||
|
||||
private Texture2D bodyShapeTexture;
|
||||
public Texture2D BodyShapeTexture
|
||||
{
|
||||
get { return bodyShapeTexture; }
|
||||
}
|
||||
|
||||
public PhysicsBody(XElement element, float scale = 1.0f)
|
||||
: this(element, Vector2.Zero, scale)
|
||||
{
|
||||
@@ -336,6 +342,15 @@ namespace Barotrauma
|
||||
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()
|
||||
{
|
||||
@@ -370,10 +385,43 @@ namespace Barotrauma
|
||||
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>
|
||||
/// rotate the body towards the target rotation in the "shortest direction"
|
||||
/// </summary>
|
||||
@@ -399,6 +447,12 @@ namespace Barotrauma
|
||||
{
|
||||
list.Remove(this);
|
||||
GameMain.World.RemoveBody(body);
|
||||
|
||||
if (bodyShapeTexture != null)
|
||||
{
|
||||
bodyShapeTexture.Dispose();
|
||||
bodyShapeTexture = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -173,12 +173,12 @@ namespace Barotrauma
|
||||
|
||||
DrawJoints(spriteBatch, limb, limbBodyPos);
|
||||
|
||||
if (limb.BodyShapeTexture == null) continue;
|
||||
//if (limb.BodyShapeTexture == null) continue;
|
||||
|
||||
spriteBatch.Draw(limb.BodyShapeTexture, limbBodyPos,
|
||||
null, Color.White, 0.0f,
|
||||
new Vector2(limb.BodyShapeTexture.Width, limb.BodyShapeTexture.Height) / 2,
|
||||
1.0f, SpriteEffects.None, 0.0f);
|
||||
//spriteBatch.Draw(limb.BodyShapeTexture, limbBodyPos,
|
||||
// null, Color.White, 0.0f,
|
||||
// new Vector2(limb.BodyShapeTexture.Width, limb.BodyShapeTexture.Height) / 2,
|
||||
// 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.UnitX * 5.0f, limbBodyPos - Vector2.UnitX * 5.0f, Color.White);
|
||||
|
||||
Reference in New Issue
Block a user