- disabling the collider and placing it on the torso when swimming, stunned or dead (todo: attempt to get swimming working with the collider controlling movement)

- only the collider can receive impact damage
- shorter collider to allow crouching in tight spaces
- AI characters are considered close enough to a waypoint if their collider overlaps with it (instead of a distance check)
This commit is contained in:
Regalis
2016-10-14 16:08:55 +03:00
parent 9d9c50a520
commit 1b59d1bc21
8 changed files with 102 additions and 70 deletions

View File

@@ -76,7 +76,7 @@
<sound file ="Content/step.ogg"/>
</limb>
<limb id = "13" height="130" radius="15" mass = "6" type="Controller" attackpriority="2" impacttolerance="5000.0">
<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>

View File

@@ -82,20 +82,20 @@ namespace Barotrauma
Character.AnimController.IgnorePlatforms = true;
}
if (Character.AnimController.Stairs != null)
{
float yDiff = currPath.CurrentNode.WorldPosition.Y - Character.WorldPosition.Y;
//if (Character.AnimController.Stairs != null)
//{
// float yDiff = currPath.CurrentNode.WorldPosition.Y - Character.WorldPosition.Y;
if (Math.Abs(yDiff)>10.0f)
{
int dir = Math.Sign(yDiff);
// if (Math.Abs(yDiff) > 20.0f)
// {
// int dir = Math.Sign(yDiff);
float movement = Character.AnimController.Stairs.StairDirection == Direction.Right ?
dir * Character.AnimController.TargetMovement.Length() : -dir * Character.AnimController.TargetMovement.Length();
// float movement = Character.AnimController.Stairs.StairDirection == Direction.Right ?
// dir * Character.AnimController.TargetMovement.Length() : -dir * Character.AnimController.TargetMovement.Length();
Character.AnimController.TargetMovement = new Vector2(movement, 0.0f);
}
}
// steeringManager.SteeringManual(deltaTime, new Vector2(movement*2, 0.0f));
// }
//}
}
(Character.AnimController as HumanoidAnimController).Crouching = false;

View File

@@ -111,7 +111,7 @@ namespace Barotrauma
if (canOpenDoors && !character.LockHands) CheckDoorsInPath();
float allowedDistance = character.AnimController.InWater ? 1.0f : 0.6f;
if (currentPath.CurrentNode!=null && currentPath.CurrentNode.SimPosition.Y > character.SimPosition.Y+1.0f) allowedDistance*=0.5f;
//if (currentPath.CurrentNode!=null && currentPath.CurrentNode.SimPosition.Y > character.SimPosition.Y+1.0f) allowedDistance*=0.5f;
Vector2 pos = host.SimPosition;
@@ -139,7 +139,16 @@ namespace Barotrauma
}
}
currentPath.CheckProgress(pos, allowedDistance);
//currentPath.CheckProgress(pos, allowedDistance);
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 &&
currentPath.CurrentNode.SimPosition.Y > colliderBottom.Y &&
currentPath.CurrentNode.SimPosition.Y < colliderBottom.Y + collider.body.height + collider.body.radius*2)
{
currentPath.SkipToNextNode();
}
if (currentPath.CurrentNode == null) return Vector2.Zero;

View File

@@ -90,11 +90,12 @@ namespace Barotrauma
escapeObjective.TryComplete(deltaTime);
if (Vector2.Distance(character.SimPosition, enemy.SimPosition) < 3.0f)
{
character.AIController.SteeringManager.SteeringManual(deltaTime, (character.SimPosition - enemy.SimPosition)*0.1f);
coolDownTimer = CoolDown;
}
//if (Vector2.Distance(character.SimPosition, enemy.SimPosition) < 3.0f)
//{
// character.AIController.SteeringManager.SteeringManual(deltaTime,
// new Vector2(Math.Sign(character.SimPosition.X - enemy.SimPosition.X), 0.0f));
// coolDownTimer = CoolDown;
//}
}
public override bool IsCompleted()

View File

@@ -61,13 +61,24 @@ namespace Barotrauma
public override void UpdateAnim(float deltaTime)
{
if (character.IsDead) return;
if (Frozen) return;
if (character.IsDead || Frozen || character.IsUnconscious || stunTimer > 0.0f)
{
collider.Disabled = true;
collider.body.PhysEnabled = false;
var lowestLimb = FindLowestLimb(true);
collider.body.SetTransform(GetLimb(LimbType.Torso).SimPosition, 0.0f);
if (stunTimer > 0)
{
stunTimer -= deltaTime;
}
return;
}
if (collider == null) return;
Vector2 colliderPos = GetColliderBottom();
//if (inWater) stairs = null;
//if (onFloorTimer <= 0.0f && !SimplePhysicsEnabled)
@@ -143,7 +154,7 @@ namespace Barotrauma
stairs = null;
var contacts = collider.body.FarseerBody.ContactList;
while (contacts != null && contacts.Contact != null)
while (collider.body.PhysEnabled && contacts != null && contacts.Contact != null)
{
if (contacts.Contact.Enabled && contacts.Contact.IsTouching)
{
@@ -215,12 +226,11 @@ namespace Barotrauma
}
strongestImpact = 0.0f;
if (stunTimer > 0)
if (collider.Disabled && !swimming)
{
collider.Disabled = true;
stunTimer -= deltaTime;
return;
var lowestLimb = FindLowestLimb(true);
collider.body.SetTransform(lowestLimb.SimPosition + Vector2.UnitY * (collider.body.radius + collider.body.height / 2), 0.0f);
collider.Disabled = false;
}
if (character.LockHands)
@@ -265,8 +275,11 @@ namespace Barotrauma
return;
}
inWater = false;
collider.body.PhysEnabled = true;
collider.body.Enabled = true;
switch (Anim)
{
case Animation.Climbing:
@@ -311,6 +324,7 @@ namespace Barotrauma
foreach (Limb limb in Limbs)
{
if (limb == collider) continue;
limb.Disabled = false;
}
@@ -339,7 +353,7 @@ namespace Barotrauma
Limb rightLeg = GetLimb(LimbType.RightLeg);
float getUpSpeed = 0.3f;
float walkCycleSpeed = head.LinearVelocity.X * walkAnimSpeed;
float walkCycleSpeed = collider.LinearVelocity.X * walkAnimSpeed;
if (stairs != null)
{
TargetMovement = new Vector2(MathHelper.Clamp(TargetMovement.X, -1.5f, 1.5f), TargetMovement.Y);
@@ -619,6 +633,11 @@ namespace Barotrauma
float surfaceLimiter = 1.0f;
Limb head = GetLimb(LimbType.Head);
Limb torso = GetLimb(LimbType.Torso);
collider.body.PhysEnabled = false;
collider.Disabled = true;
collider.body.SetTransform(torso.SimPosition, 0.0f);
if (currentHull != null && (currentHull.Rect.Y - currentHull.Surface > 50.0f) && !head.inWater)
{
@@ -627,13 +646,13 @@ namespace Barotrauma
if (surfaceLimiter > 20.0f) return;
}
Limb torso = GetLimb(LimbType.Torso);
Limb leftHand = GetLimb(LimbType.LeftHand);
Limb rightHand = GetLimb(LimbType.RightHand);
Limb leftFoot = GetLimb(LimbType.LeftFoot);
Limb rightFoot = GetLimb(LimbType.RightFoot);
float rotation = MathHelper.WrapAngle(torso.Rotation);
rotation = MathHelper.ToDegrees(rotation);
if (rotation < 0.0f) rotation += 360;

View File

@@ -30,8 +30,6 @@ namespace Barotrauma
private Character character;
private Limb lowestLimb;
protected float strongestImpact;
public float headPosition, headAngle;
@@ -275,8 +273,7 @@ namespace Barotrauma
limb.sprite.Depth = startDepth + limb.sprite.Depth * 0.0001f;
}
collider = GetLimb(LimbType.Controller);
collider = GetLimb(LimbType.Collider);
if (collider == null) return;
collider.body.FarseerBody.FixedRotation = true;
@@ -383,6 +380,10 @@ namespace Barotrauma
contact.GetWorldManifold(out normal, out points);
if (points[0].Y > collider.SimPosition.Y) return false;
//---------------
if (inWater && targetMovement.Y < 0.5f) return false;
//---------------
stairs = structure;
@@ -406,7 +407,6 @@ namespace Barotrauma
//Limb limb = f1.Body.UserData as Limb;
//if (limb != null)// && (limb.type == LimbType.LeftFoot || limb.type == LimbType.RightFoot))
//{
// if (contact.Manifold.LocalNormal.Y >= 0.0f)
@@ -425,9 +425,9 @@ namespace Barotrauma
// }
//}
}
CalculateImpact(f1, f2, contact);
return true;
}
@@ -437,39 +437,39 @@ namespace Barotrauma
Vector2 normal = contact.Manifold.LocalNormal;
Vector2 avgVelocity = Vector2.Zero;
foreach (Limb limb in Limbs)
{
avgVelocity += limb.LinearVelocity;
}
//Vector2 avgVelocity = Vector2.Zero;
//foreach (Limb limb in Limbs)
//{
// avgVelocity += limb.LinearVelocity;
//}
avgVelocity = avgVelocity / Limbs.Count();
Limb limb = (Limb)f1.Body.UserData;
Vector2 velocity = limb.LinearVelocity;
if (character.Submarine == null && f2.Body.UserData is Submarine) avgVelocity -= ((Submarine)f2.Body.UserData).Velocity;
if (character.Submarine == null && f2.Body.UserData is Submarine) velocity -= ((Submarine)f2.Body.UserData).Velocity;
float impact = Vector2.Dot(avgVelocity, -normal);
float impact = Vector2.Dot(velocity, -normal);
Limb l = (Limb)f1.Body.UserData;
float volume = stairs == null ? impact / 5.0f : impact;
volume = Math.Min(impact, 1.0f);
if (impact > 0.5f && l.HitSound != null && l.soundTimer <= 0.0f)
if (impact > 0.5f && limb.HitSound != null && limb.soundTimer <= 0.0f)
{
l.soundTimer = Limb.SoundInterval;
l.HitSound.Play(volume, impact * 250.0f, l.WorldPosition);
limb.soundTimer = Limb.SoundInterval;
limb.HitSound.Play(volume, impact * 250.0f, limb.WorldPosition);
}
if (impact > l.impactTolerance)
if (impact > limb.impactTolerance && limb == collider)
{
if (!character.IsNetworkPlayer || GameMain.Server != null)
{
character.AddDamage(CauseOfDeath.Damage, impact - l.impactTolerance * 0.1f, null);
character.AddDamage(CauseOfDeath.Damage, impact - limb.impactTolerance * 0.1f, null);
strongestImpact = Math.Max(strongestImpact, impact - l.impactTolerance);
strongestImpact = Math.Max(strongestImpact, impact - limb.impactTolerance);
}
SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, l.body);
SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, limb.body);
if (Character.Controlled == character) GameMain.GameScreen.Cam.Shake = strongestImpact;
}
@@ -765,7 +765,7 @@ namespace Barotrauma
headInWater = false;
if (currentHull.Volume > currentHull.FullVolume * 0.95f ||
ConvertUnits.ToSimUnits(currentHull.Surface) - floorY > HeadPosition * 0.95f)
ConvertUnits.ToSimUnits(currentHull.Surface) - GetColliderBottom().Y > HeadPosition * 0.95f)
inWater = true;
}
@@ -1044,18 +1044,21 @@ namespace Barotrauma
{
return collider == null ? Vector2.Zero : collider.SimPosition - Vector2.UnitY * (collider.body.height / 2 + collider.body.radius);
}
//public void FindLowestLimb()
//{ //find the lowest limb
// lowestLimb = null;
// foreach (Limb limb in Limbs)
// {
// if (lowestLimb == null)
// lowestLimb = limb;
// else if (limb.SimPosition.Y < lowestLimb.SimPosition.Y)
// lowestLimb = limb;
// }
//}
public Limb FindLowestLimb(bool ignoreCollider)
{
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)
lowestLimb = limb;
}
return lowestLimb;
}
public void Remove()
{

View File

@@ -1196,7 +1196,7 @@ namespace Barotrauma
{
foreach (Character c in CharacterList)
{
if (c.isDead || c.health <= 0.0f || !c.Enabled) continue;
if (!c.Enabled) continue;
c.AnimController.UpdateAnim(deltaTime);
}
}

View File

@@ -17,7 +17,7 @@ namespace Barotrauma
{
None, LeftHand, RightHand, LeftArm, RightArm,
LeftLeg, RightLeg, LeftFoot, RightFoot, Head, Torso, Tail, Legs, RightThigh, LeftThigh, Waist,
Controller
Collider
};
class Limb