Skip to content

Commit 2b7b67f

Browse files
committed
Excluded Automap layer from all raycasts
Made sure we keep using the implicit Physics.DefaultRaycastLayers for casts that were using that, but with Automap excluded. Added a PhysicsLayers utility script to expose that mask as a static PhysicsLayers.DefaultRaycastLayersWithoutAutomap.
1 parent 85e8357 commit 2b7b67f

28 files changed

Lines changed: 124 additions & 72 deletions

Assets/Game/Addons/RmbBlockEditor/Placeholder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using System;
99
using DaggerfallConnect.Arena2;
10+
using DaggerfallWorkshop.Game.Utility;
1011
using UnityEditor;
1112
using UnityEngine;
1213

@@ -84,7 +85,7 @@ protected void OnSceneGUI(SceneView sceneView)
8485

8586
Vector3 mousePosition = Event.current.mousePosition;
8687
Ray ray = HandleUtility.GUIPointToWorldRay(mousePosition);
87-
if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity) && !mouseHasDragged)
88+
if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap) && !mouseHasDragged)
8889
{
8990
OnRaycastHit(hit);
9091
}
@@ -351,4 +352,4 @@ protected override void OnRaycastHit(RaycastHit hit)
351352
}
352353
}
353354
#endif
354-
}
355+
}

Assets/Game/Addons/UnityConsole/Console/Scripts/DefaultCommands.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using DaggerfallWorkshop.Game.Formulas;
2020
using DaggerfallConnect;
2121
using DaggerfallWorkshop.Game.Serialization;
22+
using DaggerfallWorkshop.Game.Utility;
2223
using DaggerfallWorkshop.Utility.AssetInjection;
2324
using DaggerfallConnect.FallExe;
2425
using DaggerfallWorkshop.Game.Utility.ModSupport;
@@ -1521,7 +1522,7 @@ public static string Execute(params string[] args)
15211522
DaggerfallActionDoor door;
15221523
RaycastHit hitInfo;
15231524
Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
1524-
if (!(Physics.Raycast(ray, out hitInfo)))
1525+
if (!(Physics.Raycast(ray, out hitInfo, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)))
15251526
return error;
15261527
else
15271528
{
@@ -1550,7 +1551,7 @@ public static string Execute(params string[] args)
15501551
DaggerfallAction action;
15511552
RaycastHit hitInfo;
15521553
Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
1553-
if (!(Physics.Raycast(ray, out hitInfo)))
1554+
if (!(Physics.Raycast(ray, out hitInfo, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)))
15541555
return error;
15551556
else
15561557
{
@@ -1672,7 +1673,7 @@ public static string Execute(params string[] args)
16721673
Vector3 origin = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
16731674
Ray ray = new Ray(origin + Camera.main.transform.forward * .2f, Camera.main.transform.forward);
16741675
GameManager.Instance.AcrobatMotor.ClearFallingDamage();
1675-
if (!(Physics.Raycast(ray, out hitInfo, maxDistance)))
1676+
if (!(Physics.Raycast(ray, out hitInfo, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)))
16761677
{
16771678
Console.Log("Didn't hit anything...");
16781679
if (forceTeleOnNoHit)
@@ -2171,7 +2172,7 @@ public static string Execute(params string[] args)
21712172
Vector3 origin = frictionMotor.ContactPoint;
21722173
origin.y += cc.height;
21732174
Ray ray = new Ray(origin, Vector3.down);
2174-
if (!(Physics.Raycast(ray, out hitInfo, cc.height * 2)))
2175+
if (!(Physics.Raycast(ray, out hitInfo, cc.height * 2, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)))
21752176
{
21762177
return "Failed to reposition - try Teleport or if inside tele2exit";
21772178
}

Assets/Game/Addons/WorldDataEditor/Editor/WorldDataEditor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using DaggerfallConnect.Arena2;
1515
using DaggerfallWorkshop.Utility.AssetInjection;
1616
using DaggerfallWorkshop.Utility;
17+
using DaggerfallWorkshop.Game.Utility;
1718

1819
namespace DaggerfallWorkshop.Game.Utility.WorldDataEditor
1920
{
@@ -924,7 +925,7 @@ private void AddItemWindow()
924925
// Try to position where the camera is looking
925926
Ray newRay = new Ray(SceneView.lastActiveSceneView.camera.transform.position, SceneView.lastActiveSceneView.camera.transform.forward);
926927
RaycastHit hit = new RaycastHit();
927-
if (Physics.Raycast(newRay, out hit, 200))
928+
if (Physics.Raycast(newRay, out hit, 200, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
928929
go.transform.position = hit.point;
929930
else
930931
go.transform.position = SceneView.lastActiveSceneView.camera.transform.position + (SceneView.lastActiveSceneView.camera.transform.forward * 10);

Assets/Scripts/Game/DaggerfallMissile.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using DaggerfallWorkshop.Utility;
1515
using DaggerfallWorkshop.Game.MagicAndEffects;
1616
using DaggerfallWorkshop.Game.Entity;
17+
using DaggerfallWorkshop.Game.Utility;
1718

1819
namespace DaggerfallWorkshop.Game
1920
{
@@ -395,7 +396,7 @@ public static DaggerfallEntityBehaviour GetEntityTargetInTouchRange(Vector3 aimP
395396
RaycastHit hit;
396397
aimPosition -= aimDirection * 0.1f;
397398
Ray ray = new Ray(aimPosition, aimDirection);
398-
if (Physics.SphereCast(ray, SphereCastRadius, out hit, TouchRange))
399+
if (Physics.SphereCast(ray, SphereCastRadius, out hit, TouchRange, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
399400
return hit.transform.GetComponent<DaggerfallEntityBehaviour>();
400401
else
401402
return null;
@@ -443,7 +444,7 @@ void DoAreaOfEffect(Vector3 position, bool ignoreCaster = false)
443444
transform.position = position;
444445

445446
// Collect AOE targets and ignore duplicates
446-
Collider[] overlaps = Physics.OverlapSphere(position, ExplosionRadius);
447+
Collider[] overlaps = Physics.OverlapSphere(position, ExplosionRadius, PhysicsLayers.DefaultRaycastLayersWithoutAutomap);
447448
for (int i = 0; i < overlaps.Length; i++)
448449
{
449450
DaggerfallEntityBehaviour aoeEntity = overlaps[i].GetComponent<DaggerfallEntityBehaviour>();

Assets/Scripts/Game/EnemyMotor.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using UnityEngine;
1313
using DaggerfallWorkshop.Game.Entity;
1414
using DaggerfallWorkshop.Game.MagicAndEffects;
15+
using DaggerfallWorkshop.Game.Utility;
1516
using System.Collections.Generic;
1617
using DaggerfallWorkshop.Utility;
1718
using System.Linq;
@@ -137,10 +138,10 @@ void Start()
137138
(mobile.Enemy.HasRangedAttack1 && (!mobile.Enemy.CastsMagic || mobile.Enemy.HasRangedAttack2));
138139

139140
// Add things AI should ignore when checking for a clear path to shoot.
140-
ignoreMaskForShooting = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast"));
141+
ignoreMaskForShooting = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast") | 1 << LayerMask.NameToLayer("Automap"));
141142

142143
// Also ignore arrows and "Ignore Raycast" layer for obstacles
143-
ignoreMaskForObstacles = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast"));
144+
ignoreMaskForObstacles = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast") | 1 << LayerMask.NameToLayer("Automap"));
144145

145146
LastGroundedY = transform.position.y;
146147

@@ -222,7 +223,7 @@ public Vector3 FindGroundPosition(float distance = 16)
222223
{
223224
RaycastHit hit;
224225
Ray ray = new Ray(transform.position, Vector3.down);
225-
if (Physics.Raycast(ray, out hit, distance))
226+
if (Physics.Raycast(ray, out hit, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
226227
return hit.point;
227228

228229
return transform.position;
@@ -1188,7 +1189,7 @@ void ObstacleCheck(Vector3 direction)
11881189
p1 = transform.position + (Vector3.up * -originalHeight * 0.25f);
11891190
p2 = p1 + (Vector3.up * originalHeight * 0.75f);
11901191

1191-
if (!Physics.CapsuleCast(p1, p2, controller.radius / 2, direction, checkDistance))
1192+
if (!Physics.CapsuleCast(p1, p2, controller.radius / 2, direction, checkDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
11921193
{
11931194
ObstacleDetected = false;
11941195
foundUpwardSlope = true;
@@ -1216,7 +1217,7 @@ void FallCheck(Vector3 direction)
12161217
Ray ray = new Ray(rayOrigin + direction, Vector3.down);
12171218
RaycastHit hit;
12181219

1219-
fallDetected = !Physics.Raycast(ray, out hit, (originalHeight * 0.5f) + 1.5f);
1220+
fallDetected = !Physics.Raycast(ray, out hit, (originalHeight * 0.5f) + 1.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap);
12201221
}
12211222

12221223
/// <summary>

Assets/Scripts/Game/EnemySenses.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public Vector3 PredictNextTargetPos(float interceptSpeed)
550550

551551
// If aware of target, if distance is too far or can see nothing is there, use last known position as assumed current position
552552
if (targetInSight || targetInEarshot || (predictedTargetPos - transform.position).magnitude > SightRadius + mobile.Enemy.SightModifier
553-
|| !Physics.Raycast(transform.position, (predictedTargetPosWithoutLead - transform.position).normalized, out tempHit, SightRadius + mobile.Enemy.SightModifier))
553+
|| !Physics.Raycast(transform.position, (predictedTargetPosWithoutLead - transform.position).normalized, out tempHit, SightRadius + mobile.Enemy.SightModifier, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
554554
{
555555
assumedCurrentPosition = lastKnownTargetPos;
556556
}
@@ -605,7 +605,7 @@ public Vector3 PredictNextTargetPos(float interceptSpeed)
605605
// Don't predict target will move through obstacles (prevent predicting movement through walls)
606606
RaycastHit hit;
607607
Ray ray = new Ray(assumedCurrentPosition, (prediction - assumedCurrentPosition).normalized);
608-
if (Physics.Raycast(ray, out hit, (prediction - assumedCurrentPosition).magnitude))
608+
if (Physics.Raycast(ray, out hit, (prediction - assumedCurrentPosition).magnitude, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
609609
prediction = assumedCurrentPosition;
610610
}
611611

@@ -902,7 +902,7 @@ bool CanSeeTarget(DaggerfallEntityBehaviour target)
902902
Vector3 eyeDirectionToTarget = eyeToTarget.normalized;
903903
Ray ray = new Ray(eyePos, eyeDirectionToTarget);
904904

905-
if (Physics.Raycast(ray, out hit, SightRadius))
905+
if (Physics.Raycast(ray, out hit, SightRadius, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
906906
{
907907
// Check if hit was target
908908
DaggerfallEntityBehaviour entity = hit.transform.gameObject.GetComponent<DaggerfallEntityBehaviour>();

Assets/Scripts/Game/EnemySounds.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Collections;
1414
using DaggerfallWorkshop.Utility;
1515
using DaggerfallWorkshop.Game.Entity;
16+
using DaggerfallWorkshop.Game.Utility;
1617

1718
namespace DaggerfallWorkshop.Game
1819
{
@@ -235,7 +236,7 @@ private void SetVolumeScale()
235236
// Only checks when enemy plays attract sound, so not very expensive.
236237
RaycastHit hit;
237238
Ray ray = new Ray(transform.position, directionToPlayer);
238-
if (Physics.Raycast(ray, out hit))
239+
if (Physics.Raycast(ray, out hit, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
239240
{
240241
// Ignore player hit
241242
if (hit.transform.gameObject == player)
@@ -252,4 +253,4 @@ private void SetVolumeScale()
252253

253254
#endregion
254255
}
255-
}
256+
}

Assets/Scripts/Game/Entities/PlayerEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ public void SpawnCityGuards(bool immediateSpawn)
715715
// Check if npc sees player
716716
Vector3 eyeToTarget = playerEyePos - eyePos;
717717
Ray ray = new Ray(eyePos, eyeToTarget.normalized);
718-
if (Physics.Raycast(ray, out hit, 77.5f))
718+
if (Physics.Raycast(ray, out hit, 77.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
719719
{
720720
// Check if hit was player
721721
DaggerfallEntityBehaviour entity = hit.transform.gameObject.GetComponent<DaggerfallEntityBehaviour>();

Assets/Scripts/Game/MobilePersonMotor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ bool IsDirectionClear(MobileDirection direction)
416416
// Aim low to better detect stairs
417417
tempTargetScenePosition.y += 0.1f;
418418
Ray ray = new Ray(transform.position, tempTargetScenePosition - transform.position);
419-
bool collision = Physics.Raycast(transform.position, tempTargetScenePosition - transform.position, Vector3.Distance(transform.position, tempTargetScenePosition), ~mobileAsset.GetLayerMask());
419+
bool collision = Physics.Raycast(transform.position, tempTargetScenePosition - transform.position, Vector3.Distance(transform.position, tempTargetScenePosition), ~mobileAsset.GetLayerMask() & ~(1 << LayerMask.NameToLayer("Automap")));
420420
// Debug.DrawRay(transform.position, tempTargetScenePosition - transform.position, collision ? Color.red : Color.green, 1f);
421421
return !collision;
422422
}
@@ -545,4 +545,4 @@ private void FloatingOrigin_OnPositionUpdate(Vector3 offset)
545545

546546
#endregion
547547
}
548-
}
548+
}

Assets/Scripts/Game/Player/ClimbingMotor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public void ClimbingCheck()
317317
// boolean that means ground directly below us is too close for climbing or rappelling
318318
bool tooCloseToGroundForClimb = (((isClimbing && (inputBack || isSlipping)) || airborneGraspWall)
319319
// short circuit evaluate the raycast, also prevents bug where you could teleport across town
320-
&& Physics.Raycast(controller.transform.position, Vector3.down, controller.height / 2 + 0.12f));
320+
&& Physics.Raycast(controller.transform.position, Vector3.down, controller.height / 2 + 0.12f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap));
321321

322322
CalcFrequencyAndToleranceOfWallChecks(airborneGraspWall);
323323

@@ -371,9 +371,9 @@ public void ClimbingCheck()
371371
// Test close to front of head for backward sloping wall like Scourg Barrow and bump a little backwards
372372
// Then slightly further back for short overhangs like eaves and bump more backwards and a little upwards
373373
// Height of raycast test is extended to help ensure there is clear space above not just an angled ceiling
374-
if (!Physics.Raycast(frontTestPosition, Vector3.up, controller.height / 2 + 0.3f))
374+
if (!Physics.Raycast(frontTestPosition, Vector3.up, controller.height / 2 + 0.3f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
375375
controller.transform.position += -wallDirection * 0.1f;
376-
else if (!Physics.Raycast(backTestPosition, Vector3.up, controller.height / 2 + 0.5f))
376+
else if (!Physics.Raycast(backTestPosition, Vector3.up, controller.height / 2 + 0.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
377377
controller.transform.position += -wallDirection * 0.4f + Vector3.up * 0.3f;
378378
}
379379

@@ -588,7 +588,7 @@ private void GetClimbedWallInfo()
588588
wallDirection = -cornerNormalRay.direction;
589589
// Cast character controller shape forward to see if it is about to hit anything.
590590
Debug.DrawRay(controller.transform.position, wallDirection, Color.gray);
591-
if (Physics.CapsuleCast(p1, p2, controller.radius, wallDirection, out hit, controller.radius + 0.1f))
591+
if (Physics.CapsuleCast(p1, p2, controller.radius, wallDirection, out hit, controller.radius + 0.1f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))
592592
{
593593
// Immediately stop climbing if object not valid
594594
if (!IsClimable(hit.transform))

0 commit comments

Comments
 (0)