@@ -85,6 +85,8 @@ public class DaggerfallMissile : MonoBehaviour
8585 GameObject goModel = null ;
8686 EnemySenses enemySenses ;
8787
88+ private static int layerMaskDefault = - 1 ;
89+ private static int layerMaskPlayer = - 1 ;
8890 int layerMask ;
8991
9092 List < DaggerfallEntityBehaviour > targetEntities = new List < DaggerfallEntityBehaviour > ( ) ;
@@ -233,14 +235,27 @@ private void Start()
233235 goModel . layer = gameObject . layer ;
234236 }
235237
236- string layerName ;
238+ //if layer mask has not yet been initialized, do it now
239+ if ( layerMaskDefault == - 1 )
240+ InitializeLayerMasks ( ) ;
241+
242+ //assign layer mask
237243 if ( caster && caster != GameManager . Instance . PlayerEntityBehaviour )
238- layerName = "SpellMissiles" ;
244+ layerMask = layerMaskDefault ;
239245 else
240- layerName = "Player" ;
246+ layerMask = layerMaskPlayer ;
247+ }
241248
242- layerMask = ~ ( 1 << LayerMask . NameToLayer ( layerName ) ) ;
243- layerMask = layerMask & ~ ( 1 << LayerMask . NameToLayer ( "Ignore Raycast" ) ) ;
249+ static void InitializeLayerMasks ( )
250+ {
251+ layerMaskDefault = Physics . DefaultRaycastLayers ;
252+ layerMaskDefault &= ~ ( 1 << Physics . IgnoreRaycastLayer ) ;
253+ layerMaskDefault &= ~ ( 1 << LayerMask . NameToLayer ( "Automap" ) ) ;
254+
255+ layerMaskPlayer = Physics . DefaultRaycastLayers ;
256+ layerMaskPlayer &= ~ ( 1 << Physics . IgnoreRaycastLayer ) ;
257+ layerMaskPlayer &= ~ ( 1 << LayerMask . NameToLayer ( "Player" ) ) ;
258+ layerMaskPlayer &= ~ ( 1 << LayerMask . NameToLayer ( "Automap" ) ) ;
244259 }
245260
246261 private void Update ( )
@@ -385,14 +400,23 @@ void DoCollision(Collision collision, Collider other)
385400
386401 #region Static Methods
387402
388- public static DaggerfallEntityBehaviour GetEntityTargetInTouchRange ( Vector3 aimPosition , Vector3 aimDirection )
403+ public static DaggerfallEntityBehaviour GetEntityTargetInTouchRange ( Vector3 aimPosition , Vector3 aimDirection , int layerMaskTouch = - 1 )
389404 {
405+ //set the default layer mask if none was passed
406+ if ( layerMaskTouch == - 1 )
407+ {
408+ //Initialize the layer masks if they're still not
409+ if ( layerMaskDefault == - 1 )
410+ InitializeLayerMasks ( ) ;
411+
412+ layerMaskTouch = layerMaskDefault ;
413+ }
414+
390415 // Fire ray along caster facing
391416 // Origin point of ray is set back slightly to fix issue where strikes against target capsules touching caster capsule do not connect
392417 RaycastHit hit ;
393- aimPosition -= aimDirection * 0.1f ;
394418 Ray ray = new Ray ( aimPosition , aimDirection ) ;
395- if ( Physics . SphereCast ( ray , SphereCastRadius , out hit , TouchRange ) )
419+ if ( Physics . SphereCast ( ray , SphereCastRadius , out hit , TouchRange , layerMaskTouch ) )
396420 return hit . transform . GetComponent < DaggerfallEntityBehaviour > ( ) ;
397421 else
398422 return null ;
@@ -407,7 +431,7 @@ void DoTouch()
407431 {
408432 transform . position = caster . transform . position ;
409433
410- DaggerfallEntityBehaviour entityBehaviour = GetEntityTargetInTouchRange ( GetAimPosition ( ) , GetAimDirection ( ) ) ;
434+ DaggerfallEntityBehaviour entityBehaviour = GetEntityTargetInTouchRange ( GetAimPosition ( ) , GetAimDirection ( ) , layerMask ) ;
411435 if ( entityBehaviour && entityBehaviour != caster )
412436 {
413437 targetEntities . Add ( entityBehaviour ) ;
0 commit comments