@@ -258,6 +258,24 @@ bool PlaceFoeWilderness(GameObject[] gameObjects, bool placeEnemyBehindPlayer =
258258 bool PlaceFoeFreely ( GameObject [ ] gameObjects , Transform parent , float minDistance = 5f , float maxDistance = 20f , bool placeEnemyBehindPlayer = true , bool lineOfSight = true , int spawnTries = 15 )
259259 {
260260 const float maxFloorDistance = 4f ;
261+ const float overlapSphereRadius = 0.65f ;
262+
263+ // override min/max distance in small interior spaces.
264+ var dfInterior = GameObject . FindObjectOfType < DaggerfallInterior > ( ) ;
265+ if ( dfInterior ) {
266+ Bounds bounds = new Bounds ( dfInterior . transform . position , Vector3 . one ) ;
267+ Renderer [ ] renderers = dfInterior . GetComponentsInChildren < Renderer > ( ) ;
268+ foreach ( Renderer renderer in renderers )
269+ {
270+ bounds . Encapsulate ( renderer . bounds ) ;
271+ }
272+ Vector3 playerPos = GameManager . Instance . PlayerController . transform . position ;
273+ Vector3 boundsMin = bounds . min ;
274+ Vector3 boundsMax = bounds . max ;
275+ boundsMin . y = boundsMax . y = playerPos . y ;
276+ maxDistance = Mathf . Max ( Vector3 . Distance ( playerPos , boundsMin ) , Vector3 . Distance ( playerPos , boundsMax ) ) ;
277+ minDistance = Mathf . Min ( minDistance , maxDistance / 4f ) ;
278+ }
261279
262280 // Must have received a valid array
263281 if ( gameObjects == null || gameObjects . Length == 0 )
@@ -303,7 +321,8 @@ bool PlaceFoeFreely(GameObject[] gameObjects, Transform parent, float minDistanc
303321
304322 // Ensure this is open space
305323 spawnPos = floorHit . point + enemyCC . center + ( enemyCC . height / 2f + .5f ) * Vector3 . up ;
306- Collider [ ] colliders = Physics . OverlapCapsule ( spawnPos - enemyCC . height / 2f * Vector3 . up , spawnPos + enemyCC . height / 2f * Vector3 . up , enemyCC . radius , DFULayerMasks . CorporealMask ) ;
324+ // Collider[] colliders = Physics.OverlapCapsule(spawnPos - enemyCC.height/2f * Vector3.up, spawnPos + enemyCC.height/2f * Vector3.up, enemyCC.radius, DFULayerMasks.CorporealMask);
325+ Collider [ ] colliders = Physics . OverlapSphere ( spawnPos , overlapSphereRadius ) ;
307326 if ( colliders . Length > 0 )
308327 continue ;
309328
0 commit comments