Eaten characters disappear, tweaked the movements of the eater a bit

This commit is contained in:
Joonas Rikkonen
2017-06-21 16:55:56 +03:00
parent f0873bdae6
commit 4ac9aa09c6
5 changed files with 48 additions and 23 deletions

View File

@@ -12,6 +12,7 @@
attackpriorityrooms="50.0"
attackpriorityweaker="50"
attackprioritystronger="-60"
eatpriority="55"
sight="0.5"
hearing="1.0"
fleehealththreshold="10"
@@ -28,7 +29,7 @@
<collider width="45" radius="22"/>
<!-- head -->
<limb id = "0" radius="22" height="45" type="Head" flip="true" steerforce="1.0" armorsector="0.0,180.0" armorvalue="30.0">
<limb id = "0" radius="22" height="45" type="Head" flip="true" steerforce="1.0" armorsector="0.0,180.0" armorvalue="30.0" mouthpos="17,35">
<sprite texture="Content/Characters/Crawler/crawler.png" sourcerect="0,0,51,121" depth="0.02" origin="0.45,0.63"/>
</limb>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

View File

@@ -32,7 +32,7 @@
<collider radius="60"/>
<!-- head -->
<limb id = "0" radius="30" height="86" mass = "6" type="Head" flip="true" steerforce="1.0" armorsector="0.0,180.0" armor="10.0" mouthpos="30,88">
<limb id = "0" radius="30" height="86" mass = "6" type="Head" flip="true" steerforce="1.0" armorsector="0.0,180.0" armor="10.0" mouthpos="30,65">
<sprite texture="Content/Characters/Mantis/mantis.png" sourcerect="0,0,101,168" depth="0.02" origin="0.4,0.53"/>
</limb>
@@ -48,7 +48,7 @@
<!-- tail -->
<limb id = "3" radius="20" mass = "6" type="Tail" flip="true" armorsector="0.0,180.0" armor="10.0">
<sprite texture="Content/Characters/Mantis/mantis.png" sourcerect="130,158,46,93" depth="0.023" origin="0.37,0.3"/>
<sprite texture="Content/Characters/Mantis/mantis.png" sourcerect="133,158,46,93" depth="0.023" origin="0.37,0.3"/>
</limb>
@@ -87,7 +87,7 @@
<joint limb1="1" limb1anchor="6,-18" limb2="2" limb2anchor="-2,36" lowerlimit="-20" upperlimit="30" canbesevered="true"/>
<joint limb1="2" limb1anchor="1,7" limb2="3" limb2anchor="6,15" lowerlimit="-20" upperlimit="40" canbesevered="true"/>
<joint limb1="2" limb1anchor="1,7" limb2="3" limb2anchor="0,20" lowerlimit="-20" upperlimit="40" canbesevered="true"/>
<joint limb1="0" limb1anchor="16,2" limb2="4" limb2anchor="-5,-20" lowerlimit="-90" upperlimit="0" canbesevered="true"/>

View File

@@ -11,6 +11,7 @@
attackpriorityrooms="50.0"
attackpriorityweaker="50"
attackprioritystronger="-30"
eatpriority="55"
sight="0.5"
hearing="1.0"/>
@@ -21,7 +22,7 @@
<collider radius="50" height="320"/>
<!-- head -->
<limb id = "0" radius="12" height="100" type="Head" steerforce="1.0">
<limb id = "0" radius="12" height="100" type="Head" steerforce="1.0" mouthpos="20,0">
<sprite texture="Content/Characters/Tigerthresher/tigerthresher.png" sourcerect="371,15,66,136" depth="0.02" origin ="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Tigerthresher/damagedtigerthresher.png" sourcerect="371,15,66,136" origin ="0.5,0.5"/>
</limb>

View File

@@ -53,6 +53,8 @@ namespace Barotrauma
private AITarget selectedAiTarget;
private AITargetMemory selectedTargetMemory;
private float targetValue;
private float eatTimer;
private Dictionary<AITarget, AITargetMemory> targetMemories;
@@ -150,7 +152,11 @@ namespace Barotrauma
}
else if ((selectedAiTarget.Entity is Character) && ((Character)selectedAiTarget.Entity).IsDead)
{
state = AIState.Eat;
if (state != AIState.Eat)
{
eatTimer = 0.0f;
state = AIState.Eat;
}
}
else
{
@@ -420,7 +426,7 @@ namespace Barotrauma
private void UpdateEating(float deltaTime)
{
if (selectedAiTarget == null)
if (selectedAiTarget == null || selectedAiTarget.Entity == null || selectedAiTarget.Entity.Removed)
{
state = AIState.None;
return;
@@ -428,7 +434,7 @@ namespace Barotrauma
Limb mouthLimb = Array.Find(Character.AnimController.Limbs, l => l != null && l.MouthPos.HasValue);
if (mouthLimb == null) mouthLimb = Character.AnimController.GetLimb(LimbType.Head);
if (mouthLimb == null)
{
DebugConsole.ThrowError("Character \"" + Character.SpeciesName + "\" failed to eat a target (a head or a limb with a mouthpos required)");
@@ -436,6 +442,11 @@ namespace Barotrauma
return;
}
Character targetCharacter = selectedAiTarget.Entity as Character;
float eatSpeed = Character.Mass / targetCharacter.Mass * 0.1f;
eatTimer += deltaTime * eatSpeed;
Vector2 mouthPos = mouthLimb.SimPosition;
if (mouthLimb.MouthPos.HasValue)
{
@@ -447,37 +458,49 @@ namespace Barotrauma
mouthLimb.MouthPos.Value.X * sin + mouthLimb.MouthPos.Value.Y * cos);
}
Vector2 attackSimPosition = Character.Submarine == null ? ConvertUnits.ToSimUnits(selectedAiTarget.WorldPosition) : selectedAiTarget.SimPosition;
steeringManager.SteeringSeek(attackSimPosition + (mouthPos - SimPosition), 3);
Vector2 limbDiff = attackSimPosition - mouthPos;
float limbDist = limbDiff.Length();
if (limbDist < 1.0f)
{
Character targetCharacter = selectedAiTarget.Entity as Character;
//targetCharacter.AnimController.MainLimb.body.ApplyForce(-limbDiff * targetCharacter.AnimController.Mass * (float)(Math.Sin(Timing.TotalTime)+1.0f));
//pull the target character to the position of the mouth
//(+ make the force fluctuate to waggle the character a bit)
targetCharacter.AnimController.MainLimb.MoveToPos(mouthPos, (float)(Math.Sin(eatTimer) + 10.0f));
targetCharacter.AnimController.MainLimb.MoveToPos(
mouthPos,
(float)(Math.Sin(Timing.TotalTime) + 10.0f));
steeringManager.SteeringManual(deltaTime, limbDiff);
//pull the character's mouth to the target character (again with a fluctuating force)
float pullStrength = (float)(Math.Sin(eatTimer) * Math.Max(Math.Sin(eatTimer * 0.5f), 0.0f));
steeringManager.SteeringManual(deltaTime, limbDiff * pullStrength);
mouthLimb.body.ApplyForce(limbDiff * mouthLimb.Mass * 50.0f * pullStrength);
Character.AnimController.Collider.ApplyForce(limbDiff * mouthLimb.Mass * 50.0f, mouthPos);
mouthLimb.body.ApplyForce(limbDiff * mouthLimb.Mass * 50.0f * (float)(Math.Sin(Timing.TotalTime) + 1.0f));
//eatingLimb.pullJoint.Enabled = true;
//eatingLimb.pullJoint.WorldAnchorB = attackSimPosition;
if (Rand.Range(0.0f, 60.0f) < 1.0f)
if (eatTimer % 1.0f < 0.5f && (eatTimer - deltaTime * eatSpeed) % 1.0f > 0.5f)
{
//apply damage to the target character to get some blood particles flying
targetCharacter.AnimController.MainLimb.AddDamage(targetCharacter.SimPosition, DamageType.None, Rand.Range(10.0f, 25.0f), 10.0f, false);
//keep severing joints until there is only one limb left
LimbJoint[] nonSeveredJoints = Array.FindAll(targetCharacter.AnimController.LimbJoints, l => !l.IsSevered);
if (nonSeveredJoints.Length == 0)
{
//only one limb left, the character is now full eaten
Entity.Spawner.AddToRemoveQueue(targetCharacter);
state = AIState.None;
}
else //sever a random joint
{
targetCharacter.AnimController.SeverLimbJoint(nonSeveredJoints[Rand.Int(nonSeveredJoints.Length)]);
}
}
}
else if (limbDist < 2.0f)
{
steeringManager.SteeringManual(deltaTime, limbDiff);
Character.AnimController.Collider.ApplyForce(limbDiff * mouthLimb.Mass * 50.0f, mouthPos);
}
else
{
steeringManager.SteeringSeek(attackSimPosition + (mouthPos - SimPosition), 3);
}
}