Skip to content

Commit

Permalink
Fix regression caused by Interkarma#1861
Browse files Browse the repository at this point in the history
nuking themselves with spells at range in the presence of low obstacles.

A side effect of this PR however, is that daedra lords in the "crossbow
room" near the end of Mantellan Crux stopped shooting at the player
altogether, making this room much less threatening.

This new PR checks for obstacles a bit in front of the enemies, so they
can still cast from behind thin obstacles (rationale: spells start from
arm's reach). It's a bit crude, for example it doesn't change from where
the spells will be really cast, but from testing different casters
(namely, beside Mantellan Crux's daedra lords: Karolys lich and
Gortwog's shaman in entrance of Orsinium), I haven't experienced
regressions.
  • Loading branch information
Pierre Etchemaite committed Jul 26, 2023
1 parent 53ce636 commit 96603d5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Assets/Scripts/Game/EnemyMotor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class EnemyMotor : MonoBehaviour
const float attackSpeedDivisor = 2f; // How much to slow down during attack animations
float stopDistance = 1.7f; // Used to prevent orbiting
const float doorCrouchingHeight = 1.65f; // How low enemies dive to pass thru doors
const float armLength = 1f; // Distance of cast spells origin
bool flies; // The enemy can fly
bool swims; // The enemy can swim
bool pausePursuit; // pause to wait for the player to come closer to ground
Expand Down Expand Up @@ -677,6 +678,9 @@ bool HasClearPathToShootProjectile(float speed, float radius)
if (sphereCastDir == EnemySenses.ResetPlayerPos)
return false;

float sphereCastDist = (sphereCastDir - transform.position).magnitude;
sphereCastDir = (sphereCastDir - transform.position).normalized;

// No point blank shooting special handling here, makes enemies favor other attack types (melee, touch spells,...)

bool myColliderWasEnabled = false;
Expand All @@ -686,16 +690,13 @@ bool HasClearPathToShootProjectile(float speed, float radius)
// Exclude enemy collider from CheckSphere test
myCollider.enabled = false;
}
bool isSpaceInsufficient = Physics.CheckSphere(transform.position, radius, ignoreMaskForShooting);
bool isSpaceInsufficient = Physics.CheckSphere(transform.position + sphereCastDir * armLength, radius, ignoreMaskForShooting);
if (myCollider)
myCollider.enabled = myColliderWasEnabled;

if (isSpaceInsufficient)
return false;

float sphereCastDist = (sphereCastDir - transform.position).magnitude;
sphereCastDir = (sphereCastDir - transform.position).normalized;

RaycastHit hit;
if (Physics.SphereCast(transform.position, radius, sphereCastDir, out hit, sphereCastDist, ignoreMaskForShooting))
{
Expand Down

0 comments on commit 96603d5

Please sign in to comment.