Fixed AI characters being able to attack through walls. Closes #901
This commit is contained in:
@@ -446,28 +446,34 @@ namespace Barotrauma
|
|||||||
body.ApplyTorque(Mass * character.AnimController.Dir * attack.Torque);
|
body.ApplyTorque(Mass * character.AnimController.Dir * attack.Torque);
|
||||||
|
|
||||||
bool wasHit = false;
|
bool wasHit = false;
|
||||||
|
|
||||||
if (damageTarget != null)
|
if (damageTarget != null)
|
||||||
{
|
{
|
||||||
switch (attack.HitDetectionType)
|
switch (attack.HitDetectionType)
|
||||||
{
|
{
|
||||||
case HitDetection.Distance:
|
case HitDetection.Distance:
|
||||||
wasHit = dist < attack.DamageRange;
|
if (dist < attack.DamageRange)
|
||||||
|
{
|
||||||
|
List<Body> ignoredBodies = character.AnimController.Limbs.Select(l => l.body.FarseerBody).ToList();
|
||||||
|
ignoredBodies.Add(character.AnimController.Collider.FarseerBody);
|
||||||
|
|
||||||
|
var body = Submarine.PickBody(
|
||||||
|
SimPosition, attackPosition,
|
||||||
|
ignoredBodies, Physics.CollisionWall);
|
||||||
|
|
||||||
|
wasHit = body == null;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case HitDetection.Contact:
|
case HitDetection.Contact:
|
||||||
List<Body> targetBodies = new List<Body>();
|
List<Body> targetBodies = new List<Body>();
|
||||||
if (damageTarget is Character)
|
if (damageTarget is Character targetCharacter)
|
||||||
{
|
{
|
||||||
Character targetCharacter = (Character)damageTarget;
|
|
||||||
foreach (Limb limb in targetCharacter.AnimController.Limbs)
|
foreach (Limb limb in targetCharacter.AnimController.Limbs)
|
||||||
{
|
{
|
||||||
if (!limb.IsSevered && limb.body?.FarseerBody != null) targetBodies.Add(limb.body.FarseerBody);
|
if (!limb.IsSevered && limb.body?.FarseerBody != null) targetBodies.Add(limb.body.FarseerBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (damageTarget is Structure)
|
else if (damageTarget is Structure targetStructure)
|
||||||
{
|
{
|
||||||
Structure targetStructure = (Structure)damageTarget;
|
|
||||||
|
|
||||||
if (character.Submarine == null && targetStructure.Submarine != null)
|
if (character.Submarine == null && targetStructure.Submarine != null)
|
||||||
{
|
{
|
||||||
targetBodies.Add(targetStructure.Submarine.PhysicsBody.FarseerBody);
|
targetBodies.Add(targetStructure.Submarine.PhysicsBody.FarseerBody);
|
||||||
|
|||||||
Reference in New Issue
Block a user