Skip to content

Commit

Permalink
Merge pull request #1861 from petchema/careful-casters
Browse files Browse the repository at this point in the history
Prevent point blank spellcasting into low obstacles
  • Loading branch information
Interkarma committed Aug 15, 2020
2 parents 0daf8d5 + 94d9565 commit 8039b4c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Assets/Scripts/Game/EnemyMotor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class EnemyMotor : MonoBehaviour
Vector3 detourDestination;
CharacterController controller;
DaggerfallMobileUnit mobile;
Collider myCollider;
DaggerfallEntityBehaviour entityBehaviour;
EnemyBlood entityBlood;
EntityEffectManager entityEffectManager;
Expand All @@ -103,6 +104,7 @@ void Start()
senses = GetComponent<EnemySenses>();
controller = GetComponent<CharacterController>();
mobile = GetComponentInChildren<DaggerfallMobileUnit>();
myCollider = gameObject.GetComponent<Collider>();
IsHostile = mobile.Summary.Enemy.Reactions == MobileReactions.Hostile;
flies = CanFly();
swims = mobile.Summary.Enemy.Behaviour == MobileBehaviour.Aquatic;
Expand Down Expand Up @@ -651,6 +653,22 @@ bool HasClearPathToShootProjectile(float speed, float radius)
if (sphereCastDir == EnemySenses.ResetPlayerPos)
return false;

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

bool myColliderWasEnabled = false;
if (myCollider)
{
myColliderWasEnabled = myCollider.enabled;
// Exclude enemy collider from CheckSphere test
myCollider.enabled = false;
}
bool isSpaceInsufficient = Physics.CheckSphere(transform.position, radius, ignoreMaskForShooting);
if (myCollider)
myCollider.enabled = myColliderWasEnabled;

if (isSpaceInsufficient)
return false;

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

Expand Down

0 comments on commit 8039b4c

Please sign in to comment.