From 85e83577342090a69d9012a849eb002da9458033 Mon Sep 17 00:00:00 2001 From: Vivian V Wing Date: Sat, 23 May 2026 20:22:51 -0700 Subject: [PATCH 1/5] Optimized Automap Moved Automap onto its own non-interacting physics layer, so we don't have to constantly enable/disable its game objects. This is a *huge* performance boost in large dungeons. Also we now destroy the generated geo immediately on transition to the outside. This could wait, before, because the geo was disabled; but now that we don't disable geo, we need to do it immediately. --- Assets/Scripts/Game/Automap.cs | 53 ++++++--------------------- ProjectSettings/DynamicsManager.asset | 2 +- 2 files changed, 13 insertions(+), 42 deletions(-) diff --git a/Assets/Scripts/Game/Automap.cs b/Assets/Scripts/Game/Automap.cs index a757a91905..dbe45a1551 100644 --- a/Assets/Scripts/Game/Automap.cs +++ b/Assets/Scripts/Game/Automap.cs @@ -406,8 +406,6 @@ public void UpdateAutomapStateOnWindowPush() // since new teleporters could have been discovered by pc since last time map was open this must be checked here CreateTeleporterMarkers(); - SetActivationStateOfMapObjects(true); - gameobjectPlayerMarkerArrow.transform.position = gameObjectPlayerAdvanced.transform.position; gameobjectPlayerMarkerArrow.transform.rotation = gameObjectPlayerAdvanced.transform.rotation; @@ -429,12 +427,6 @@ public void UpdateAutomapStateOnWindowPush() /// public void UpdateAutomapStateOnWindowPop() { - // about SetActivationStateOfMapObjects(false): - // this will not be enough if we will eventually allow gui windows to be opened while exploring the world - // then it will be necessary to either only disable the colliders on the automap level geometry or - // make player collision ignore colliders of objects in automap layer - I would clearly prefer this option - SetActivationStateOfMapObjects(false); - if ((GameManager.Instance.PlayerEnterExit.IsPlayerInside) && ((GameManager.Instance.PlayerEnterExit.IsPlayerInsideBuilding) || (GameManager.Instance.PlayerEnterExit.IsPlayerInsideDungeon) || (GameManager.Instance.PlayerEnterExit.IsPlayerInsideDungeonCastle))) { // and get rid of lights used to light the automap level geometry @@ -1154,9 +1146,6 @@ void CheckForNewlyDiscoveredMeshes() if ((gameobjectGeometry != null) && ((GameManager.Instance.IsPlayerInsideBuilding) || (GameManager.Instance.IsPlayerInsideDungeon) || (GameManager.Instance.IsPlayerInsideCastle))) { - // enable automap level geometry for revealing (so raycasts can hit colliders of automap level geometry) - gameobjectGeometry.SetActive(true); - // reveal geometry right below player - raycast down from player head position Vector3 rayStartPos = gameObjectPlayerAdvanced.transform.position + Camera.main.transform.localPosition; Vector3 rayDirection = Vector3.down; @@ -1189,9 +1178,6 @@ void CheckForNewlyDiscoveredMeshes() ScanWithRaycastInDirectionAndUpdateMeshesAndMaterials(rayStartPos + stepVector, rayDirection, rayDistance, offsetSecondProtectionRaycast); } } - - // disable gameobjectGeometry so player movement won't be affected by geometry colliders of automap level geometry - gameobjectGeometry.SetActive(false); } // entrance marker discovery check - only do as long as undiscovered @@ -1281,7 +1267,7 @@ IEnumerator CoroutineCheckForNewlyDiscoveredMeshes() { while (true) { - // only proceed if automap is not opened (otherwise command gameobjectGeometry.SetActive(false); will mess with automap rendering when scheduling is a bitch and overwrites changes from UpdateAutomapStateOnWindowPush() + // only update discovery while automap is closed if (!isOpenAutomap) { CheckForNewlyDiscoveredMeshes(); @@ -1315,25 +1301,6 @@ private void UpdateSlicingPositionY() // material.renderQueue = 3000; //} - /// - /// sets active state of map GameObjects like geometry, beacons, user note markers and teleporter markers - /// used on automap open to enable (show) objects and hide them on automap close - /// it is important to set them inactive when closing the map - so that ingame raycasts won't hit colliders of map objects - /// - /// the desired activation state for the map objects to be set - private void SetActivationStateOfMapObjects(bool active) - { - gameobjectGeometry.SetActive(active); - - gameobjectBeacons.SetActive(active); - - if (gameObjectUserNoteMarkers != null) - gameObjectUserNoteMarkers.SetActive(active); - - if (gameobjectTeleporterMarkers != null) - gameobjectTeleporterMarkers.SetActive(active); - } - /// /// setup beacons: lazy creation of player marker arrow and beacons including /// player position beacon, dungeon entrance position beacon and rotation pivot axis position beacon @@ -1622,8 +1589,6 @@ private void AddTeleporterMarkerOnMap(TeleporterTransform startPoint, Teleporter gameobjectTeleporterMarkers.layer = layerAutomap; } - gameobjectTeleporterMarkers.SetActive(false); - string teleporterEntranceName = NameGameobjectTeleporterSubStringStart + dictkey + NameGameobjectTeleporterEntranceSubStringEnd; if (gameobjectTeleporterMarkers.transform.Find(teleporterEntranceName) == null) { @@ -2484,16 +2449,12 @@ void InitWhenInInteriorOrDungeon(StaticDoor? door = null, bool initFromLoadingSa CreateIndoorGeometryForAutomap(door.Value); RestoreStateAutomapDungeon(true); resetAutomapSettingsFromExternalScript = true; // set flag so external script (DaggerfallAutomapWindow) can pull flag and reset automap values on next window push - - SetActivationStateOfMapObjects(false); } else if ((GameManager.Instance.IsPlayerInsideDungeon) || (GameManager.Instance.IsPlayerInsideCastle)) { CreateDungeonGeometryForAutomap(); RestoreStateAutomapDungeon(!initFromLoadingSave); // if a save game was loaded, do not reset the revisited state (don't set parameter forceNotVisitedInThisRun to true) resetAutomapSettingsFromExternalScript = true; // set flag so external script (DaggerfallAutomapWindow) can pull flag and reset automap values on next window push - - SetActivationStateOfMapObjects(false); } else { @@ -2525,12 +2486,22 @@ private void OnTransitionToExterior(PlayerEnterExit.TransitionEventArgs args) { SaveStateAutomapInterior(); DestroyBeacons(); + if (gameobjectGeometry != null) + { + UnityEngine.Object.Destroy(gameobjectGeometry); + gameobjectGeometry = null; + } } private void OnTransitionToDungeonExterior(PlayerEnterExit.TransitionEventArgs args) { SaveStateAutomapDungeon(true); DestroyBeacons(); + if (gameobjectGeometry != null) + { + UnityEngine.Object.Destroy(gameobjectGeometry); + gameobjectGeometry = null; + } } void OnLoadEvent(SaveData_v1 saveData) @@ -2731,4 +2702,4 @@ public static int AddNext(this SortedList sortedList, T item) } #endregion -} \ No newline at end of file +} diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index 072072799c..5a17e6497b 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -17,7 +17,7 @@ PhysicsManager: m_ClothInterCollisionDistance: 0 m_ClothInterCollisionStiffness: 0 m_ContactsGeneration: 1 - m_LayerCollisionMatrix: fffffefffffffeffffbffefffffffffffffffefffffffefffffffffffffffffffffffefffffffefffffffefffffffefffffffefffffffefffbbffefffffffeffc800fe0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffffefffffffefffffffeff + m_LayerCollisionMatrix: fffbfefffffbfeffffbbfefffffffffffffbfefffffbfefffffffffffffffffffffbfefffffbfeffc804fe0ffffbfefffffbfefffffbfefffbbbfefffffbfeffc800fe0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfefffffbfefffffbfefffffbfeff m_AutoSimulation: 1 m_AutoSyncTransforms: 1 m_ReuseCollisionCallbacks: 0 From 2b7b67fbbbabcfc09f39e1b51760da17f8d18e1b Mon Sep 17 00:00:00 2001 From: Vivian V Wing Date: Sun, 7 Jun 2026 22:18:33 -0700 Subject: [PATCH 2/5] 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. --- .../Game/Addons/RmbBlockEditor/Placeholder.cs | 5 ++-- .../Console/Scripts/DefaultCommands.cs | 9 ++++--- .../WorldDataEditor/Editor/WorldDataEditor.cs | 3 ++- Assets/Scripts/Game/DaggerfallMissile.cs | 5 ++-- Assets/Scripts/Game/EnemyMotor.cs | 11 ++++---- Assets/Scripts/Game/EnemySenses.cs | 6 ++--- Assets/Scripts/Game/EnemySounds.cs | 5 ++-- Assets/Scripts/Game/Entities/PlayerEntity.cs | 2 +- Assets/Scripts/Game/MobilePersonMotor.cs | 4 +-- Assets/Scripts/Game/Player/ClimbingMotor.cs | 8 +++--- Assets/Scripts/Game/Player/FrictionMotor.cs | 11 ++++---- Assets/Scripts/Game/Player/HangingMotor.cs | 3 ++- .../Game/Player/PlayerHeightChanger.cs | 3 ++- .../Scripts/Game/Player/PlayerMoveScanner.cs | 11 ++++---- Assets/Scripts/Game/PlayerActivate.cs | 4 +-- Assets/Scripts/Game/PlayerEnterExit.cs | 3 ++- Assets/Scripts/Game/PlayerMotor.cs | 10 +++---- .../Game/Questing/Actions/CreateFoe.cs | 8 +++--- Assets/Scripts/Game/Utility/FoeSpawner.cs | 8 +++--- Assets/Scripts/Game/Utility/PhysicsLayers.cs | 26 +++++++++++++++++++ .../Game/Utility/PhysicsLayers.cs.meta | 11 ++++++++ Assets/Scripts/Game/WeaponManager.cs | 2 +- Assets/Scripts/Terrain/StreamingWorld.cs | 4 +-- .../AssetInjection/Components/FaceWall.cs | 11 ++++---- .../Components/NPCModelRotator.cs | 5 ++-- .../Components/ObjectPositioner.cs | 5 ++-- .../Components/WallPropPositioner.cs | 7 ++--- Assets/Scripts/Utility/GameObjectHelper.cs | 6 ++--- 28 files changed, 124 insertions(+), 72 deletions(-) create mode 100644 Assets/Scripts/Game/Utility/PhysicsLayers.cs create mode 100644 Assets/Scripts/Game/Utility/PhysicsLayers.cs.meta diff --git a/Assets/Game/Addons/RmbBlockEditor/Placeholder.cs b/Assets/Game/Addons/RmbBlockEditor/Placeholder.cs index 92100e080c..e57387a66d 100644 --- a/Assets/Game/Addons/RmbBlockEditor/Placeholder.cs +++ b/Assets/Game/Addons/RmbBlockEditor/Placeholder.cs @@ -7,6 +7,7 @@ using System; using DaggerfallConnect.Arena2; +using DaggerfallWorkshop.Game.Utility; using UnityEditor; using UnityEngine; @@ -84,7 +85,7 @@ protected void OnSceneGUI(SceneView sceneView) Vector3 mousePosition = Event.current.mousePosition; Ray ray = HandleUtility.GUIPointToWorldRay(mousePosition); - if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity) && !mouseHasDragged) + if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap) && !mouseHasDragged) { OnRaycastHit(hit); } @@ -351,4 +352,4 @@ protected override void OnRaycastHit(RaycastHit hit) } } #endif -} \ No newline at end of file +} diff --git a/Assets/Game/Addons/UnityConsole/Console/Scripts/DefaultCommands.cs b/Assets/Game/Addons/UnityConsole/Console/Scripts/DefaultCommands.cs index d675df1149..52c51c2264 100644 --- a/Assets/Game/Addons/UnityConsole/Console/Scripts/DefaultCommands.cs +++ b/Assets/Game/Addons/UnityConsole/Console/Scripts/DefaultCommands.cs @@ -19,6 +19,7 @@ using DaggerfallWorkshop.Game.Formulas; using DaggerfallConnect; using DaggerfallWorkshop.Game.Serialization; +using DaggerfallWorkshop.Game.Utility; using DaggerfallWorkshop.Utility.AssetInjection; using DaggerfallConnect.FallExe; using DaggerfallWorkshop.Game.Utility.ModSupport; @@ -1521,7 +1522,7 @@ public static string Execute(params string[] args) DaggerfallActionDoor door; RaycastHit hitInfo; Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); - if (!(Physics.Raycast(ray, out hitInfo))) + if (!(Physics.Raycast(ray, out hitInfo, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))) return error; else { @@ -1550,7 +1551,7 @@ public static string Execute(params string[] args) DaggerfallAction action; RaycastHit hitInfo; Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); - if (!(Physics.Raycast(ray, out hitInfo))) + if (!(Physics.Raycast(ray, out hitInfo, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))) return error; else { @@ -1672,7 +1673,7 @@ public static string Execute(params string[] args) Vector3 origin = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); Ray ray = new Ray(origin + Camera.main.transform.forward * .2f, Camera.main.transform.forward); GameManager.Instance.AcrobatMotor.ClearFallingDamage(); - if (!(Physics.Raycast(ray, out hitInfo, maxDistance))) + if (!(Physics.Raycast(ray, out hitInfo, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))) { Console.Log("Didn't hit anything..."); if (forceTeleOnNoHit) @@ -2171,7 +2172,7 @@ public static string Execute(params string[] args) Vector3 origin = frictionMotor.ContactPoint; origin.y += cc.height; Ray ray = new Ray(origin, Vector3.down); - if (!(Physics.Raycast(ray, out hitInfo, cc.height * 2))) + if (!(Physics.Raycast(ray, out hitInfo, cc.height * 2, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))) { return "Failed to reposition - try Teleport or if inside tele2exit"; } diff --git a/Assets/Game/Addons/WorldDataEditor/Editor/WorldDataEditor.cs b/Assets/Game/Addons/WorldDataEditor/Editor/WorldDataEditor.cs index a483235ccc..70a6bfbab2 100644 --- a/Assets/Game/Addons/WorldDataEditor/Editor/WorldDataEditor.cs +++ b/Assets/Game/Addons/WorldDataEditor/Editor/WorldDataEditor.cs @@ -14,6 +14,7 @@ using DaggerfallConnect.Arena2; using DaggerfallWorkshop.Utility.AssetInjection; using DaggerfallWorkshop.Utility; +using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Game.Utility.WorldDataEditor { @@ -924,7 +925,7 @@ private void AddItemWindow() // Try to position where the camera is looking Ray newRay = new Ray(SceneView.lastActiveSceneView.camera.transform.position, SceneView.lastActiveSceneView.camera.transform.forward); RaycastHit hit = new RaycastHit(); - if (Physics.Raycast(newRay, out hit, 200)) + if (Physics.Raycast(newRay, out hit, 200, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) go.transform.position = hit.point; else go.transform.position = SceneView.lastActiveSceneView.camera.transform.position + (SceneView.lastActiveSceneView.camera.transform.forward * 10); diff --git a/Assets/Scripts/Game/DaggerfallMissile.cs b/Assets/Scripts/Game/DaggerfallMissile.cs index e19184f823..415cb69e91 100644 --- a/Assets/Scripts/Game/DaggerfallMissile.cs +++ b/Assets/Scripts/Game/DaggerfallMissile.cs @@ -14,6 +14,7 @@ using DaggerfallWorkshop.Utility; using DaggerfallWorkshop.Game.MagicAndEffects; using DaggerfallWorkshop.Game.Entity; +using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Game { @@ -395,7 +396,7 @@ public static DaggerfallEntityBehaviour GetEntityTargetInTouchRange(Vector3 aimP RaycastHit hit; aimPosition -= aimDirection * 0.1f; Ray ray = new Ray(aimPosition, aimDirection); - if (Physics.SphereCast(ray, SphereCastRadius, out hit, TouchRange)) + if (Physics.SphereCast(ray, SphereCastRadius, out hit, TouchRange, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return hit.transform.GetComponent(); else return null; @@ -443,7 +444,7 @@ void DoAreaOfEffect(Vector3 position, bool ignoreCaster = false) transform.position = position; // Collect AOE targets and ignore duplicates - Collider[] overlaps = Physics.OverlapSphere(position, ExplosionRadius); + Collider[] overlaps = Physics.OverlapSphere(position, ExplosionRadius, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); for (int i = 0; i < overlaps.Length; i++) { DaggerfallEntityBehaviour aoeEntity = overlaps[i].GetComponent(); diff --git a/Assets/Scripts/Game/EnemyMotor.cs b/Assets/Scripts/Game/EnemyMotor.cs index 528c1c67be..cdc2666000 100644 --- a/Assets/Scripts/Game/EnemyMotor.cs +++ b/Assets/Scripts/Game/EnemyMotor.cs @@ -12,6 +12,7 @@ using UnityEngine; using DaggerfallWorkshop.Game.Entity; using DaggerfallWorkshop.Game.MagicAndEffects; +using DaggerfallWorkshop.Game.Utility; using System.Collections.Generic; using DaggerfallWorkshop.Utility; using System.Linq; @@ -137,10 +138,10 @@ void Start() (mobile.Enemy.HasRangedAttack1 && (!mobile.Enemy.CastsMagic || mobile.Enemy.HasRangedAttack2)); // Add things AI should ignore when checking for a clear path to shoot. - ignoreMaskForShooting = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast")); + ignoreMaskForShooting = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast") | 1 << LayerMask.NameToLayer("Automap")); // Also ignore arrows and "Ignore Raycast" layer for obstacles - ignoreMaskForObstacles = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast")); + ignoreMaskForObstacles = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast") | 1 << LayerMask.NameToLayer("Automap")); LastGroundedY = transform.position.y; @@ -222,7 +223,7 @@ public Vector3 FindGroundPosition(float distance = 16) { RaycastHit hit; Ray ray = new Ray(transform.position, Vector3.down); - if (Physics.Raycast(ray, out hit, distance)) + if (Physics.Raycast(ray, out hit, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return hit.point; return transform.position; @@ -1188,7 +1189,7 @@ void ObstacleCheck(Vector3 direction) p1 = transform.position + (Vector3.up * -originalHeight * 0.25f); p2 = p1 + (Vector3.up * originalHeight * 0.75f); - if (!Physics.CapsuleCast(p1, p2, controller.radius / 2, direction, checkDistance)) + if (!Physics.CapsuleCast(p1, p2, controller.radius / 2, direction, checkDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { ObstacleDetected = false; foundUpwardSlope = true; @@ -1216,7 +1217,7 @@ void FallCheck(Vector3 direction) Ray ray = new Ray(rayOrigin + direction, Vector3.down); RaycastHit hit; - fallDetected = !Physics.Raycast(ray, out hit, (originalHeight * 0.5f) + 1.5f); + fallDetected = !Physics.Raycast(ray, out hit, (originalHeight * 0.5f) + 1.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); } /// diff --git a/Assets/Scripts/Game/EnemySenses.cs b/Assets/Scripts/Game/EnemySenses.cs index a2fcd18daa..0468af5462 100644 --- a/Assets/Scripts/Game/EnemySenses.cs +++ b/Assets/Scripts/Game/EnemySenses.cs @@ -550,7 +550,7 @@ public Vector3 PredictNextTargetPos(float interceptSpeed) // If aware of target, if distance is too far or can see nothing is there, use last known position as assumed current position if (targetInSight || targetInEarshot || (predictedTargetPos - transform.position).magnitude > SightRadius + mobile.Enemy.SightModifier - || !Physics.Raycast(transform.position, (predictedTargetPosWithoutLead - transform.position).normalized, out tempHit, SightRadius + mobile.Enemy.SightModifier)) + || !Physics.Raycast(transform.position, (predictedTargetPosWithoutLead - transform.position).normalized, out tempHit, SightRadius + mobile.Enemy.SightModifier, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { assumedCurrentPosition = lastKnownTargetPos; } @@ -605,7 +605,7 @@ public Vector3 PredictNextTargetPos(float interceptSpeed) // Don't predict target will move through obstacles (prevent predicting movement through walls) RaycastHit hit; Ray ray = new Ray(assumedCurrentPosition, (prediction - assumedCurrentPosition).normalized); - if (Physics.Raycast(ray, out hit, (prediction - assumedCurrentPosition).magnitude)) + if (Physics.Raycast(ray, out hit, (prediction - assumedCurrentPosition).magnitude, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) prediction = assumedCurrentPosition; } @@ -902,7 +902,7 @@ bool CanSeeTarget(DaggerfallEntityBehaviour target) Vector3 eyeDirectionToTarget = eyeToTarget.normalized; Ray ray = new Ray(eyePos, eyeDirectionToTarget); - if (Physics.Raycast(ray, out hit, SightRadius)) + if (Physics.Raycast(ray, out hit, SightRadius, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { // Check if hit was target DaggerfallEntityBehaviour entity = hit.transform.gameObject.GetComponent(); diff --git a/Assets/Scripts/Game/EnemySounds.cs b/Assets/Scripts/Game/EnemySounds.cs index f2fe46d159..7a79ee687d 100644 --- a/Assets/Scripts/Game/EnemySounds.cs +++ b/Assets/Scripts/Game/EnemySounds.cs @@ -13,6 +13,7 @@ using System.Collections; using DaggerfallWorkshop.Utility; using DaggerfallWorkshop.Game.Entity; +using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Game { @@ -235,7 +236,7 @@ private void SetVolumeScale() // Only checks when enemy plays attract sound, so not very expensive. RaycastHit hit; Ray ray = new Ray(transform.position, directionToPlayer); - if (Physics.Raycast(ray, out hit)) + if (Physics.Raycast(ray, out hit, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { // Ignore player hit if (hit.transform.gameObject == player) @@ -252,4 +253,4 @@ private void SetVolumeScale() #endregion } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Game/Entities/PlayerEntity.cs b/Assets/Scripts/Game/Entities/PlayerEntity.cs index 3526852cef..408d57973f 100644 --- a/Assets/Scripts/Game/Entities/PlayerEntity.cs +++ b/Assets/Scripts/Game/Entities/PlayerEntity.cs @@ -715,7 +715,7 @@ public void SpawnCityGuards(bool immediateSpawn) // Check if npc sees player Vector3 eyeToTarget = playerEyePos - eyePos; Ray ray = new Ray(eyePos, eyeToTarget.normalized); - if (Physics.Raycast(ray, out hit, 77.5f)) + if (Physics.Raycast(ray, out hit, 77.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { // Check if hit was player DaggerfallEntityBehaviour entity = hit.transform.gameObject.GetComponent(); diff --git a/Assets/Scripts/Game/MobilePersonMotor.cs b/Assets/Scripts/Game/MobilePersonMotor.cs index b337664001..069cc8ad0b 100644 --- a/Assets/Scripts/Game/MobilePersonMotor.cs +++ b/Assets/Scripts/Game/MobilePersonMotor.cs @@ -416,7 +416,7 @@ bool IsDirectionClear(MobileDirection direction) // Aim low to better detect stairs tempTargetScenePosition.y += 0.1f; Ray ray = new Ray(transform.position, tempTargetScenePosition - transform.position); - bool collision = Physics.Raycast(transform.position, tempTargetScenePosition - transform.position, Vector3.Distance(transform.position, tempTargetScenePosition), ~mobileAsset.GetLayerMask()); + bool collision = Physics.Raycast(transform.position, tempTargetScenePosition - transform.position, Vector3.Distance(transform.position, tempTargetScenePosition), ~mobileAsset.GetLayerMask() & ~(1 << LayerMask.NameToLayer("Automap"))); // Debug.DrawRay(transform.position, tempTargetScenePosition - transform.position, collision ? Color.red : Color.green, 1f); return !collision; } @@ -545,4 +545,4 @@ private void FloatingOrigin_OnPositionUpdate(Vector3 offset) #endregion } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Game/Player/ClimbingMotor.cs b/Assets/Scripts/Game/Player/ClimbingMotor.cs index 2816a8628b..fc8e3200a9 100644 --- a/Assets/Scripts/Game/Player/ClimbingMotor.cs +++ b/Assets/Scripts/Game/Player/ClimbingMotor.cs @@ -317,7 +317,7 @@ public void ClimbingCheck() // boolean that means ground directly below us is too close for climbing or rappelling bool tooCloseToGroundForClimb = (((isClimbing && (inputBack || isSlipping)) || airborneGraspWall) // short circuit evaluate the raycast, also prevents bug where you could teleport across town - && Physics.Raycast(controller.transform.position, Vector3.down, controller.height / 2 + 0.12f)); + && Physics.Raycast(controller.transform.position, Vector3.down, controller.height / 2 + 0.12f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)); CalcFrequencyAndToleranceOfWallChecks(airborneGraspWall); @@ -371,9 +371,9 @@ public void ClimbingCheck() // Test close to front of head for backward sloping wall like Scourg Barrow and bump a little backwards // Then slightly further back for short overhangs like eaves and bump more backwards and a little upwards // Height of raycast test is extended to help ensure there is clear space above not just an angled ceiling - if (!Physics.Raycast(frontTestPosition, Vector3.up, controller.height / 2 + 0.3f)) + if (!Physics.Raycast(frontTestPosition, Vector3.up, controller.height / 2 + 0.3f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) controller.transform.position += -wallDirection * 0.1f; - else if (!Physics.Raycast(backTestPosition, Vector3.up, controller.height / 2 + 0.5f)) + else if (!Physics.Raycast(backTestPosition, Vector3.up, controller.height / 2 + 0.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) controller.transform.position += -wallDirection * 0.4f + Vector3.up * 0.3f; } @@ -588,7 +588,7 @@ private void GetClimbedWallInfo() wallDirection = -cornerNormalRay.direction; // Cast character controller shape forward to see if it is about to hit anything. Debug.DrawRay(controller.transform.position, wallDirection, Color.gray); - if (Physics.CapsuleCast(p1, p2, controller.radius, wallDirection, out hit, controller.radius + 0.1f)) + if (Physics.CapsuleCast(p1, p2, controller.radius, wallDirection, out hit, controller.radius + 0.1f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { // Immediately stop climbing if object not valid if (!IsClimable(hit.transform)) diff --git a/Assets/Scripts/Game/Player/FrictionMotor.cs b/Assets/Scripts/Game/Player/FrictionMotor.cs index e735e1f92d..1eadefabb9 100644 --- a/Assets/Scripts/Game/Player/FrictionMotor.cs +++ b/Assets/Scripts/Game/Player/FrictionMotor.cs @@ -1,5 +1,6 @@ using DaggerfallConnect; using DaggerfallWorkshop.Game; +using DaggerfallWorkshop.Game.Utility; using DaggerfallWorkshop.Utility; using System.Collections; using System.Collections.Generic; @@ -99,7 +100,7 @@ private void SetSliding() sliding = false; // See if surface immediately below should be slid down. We use this normally rather than a ControllerColliderHit point, // because that interferes with step climbing amongst other annoyances - if (Physics.Raycast(myTransform.position, -Vector3.up, out hit, rayDistance)) + if (Physics.Raycast(myTransform.position, -Vector3.up, out hit, rayDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit) sliding = true; @@ -108,7 +109,7 @@ private void SetSliding() // So if the above raycast didn't catch anything, raycast down from the stored ControllerColliderHit point instead else { - Physics.Raycast(contactPoint + Vector3.up, -Vector3.up, out hit); + Physics.Raycast(contactPoint + Vector3.up, -Vector3.up, out hit, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit) sliding = true; } @@ -128,8 +129,8 @@ void HeadDipHandling() Ray headRay = new Ray(myTransform.position + new Vector3(0, heightChanger.FixedControllerStandingHeight / 2 + 0.25f, 0), myTransform.forward); Ray eyeRay = new Ray(GameManager.Instance.MainCamera.transform.position, myTransform.forward); RaycastHit headHit; - bool headRayHit = Physics.Raycast(headRay, out headHit, raySampleDistance); - bool eyeRayHit = Physics.Raycast(eyeRay, raySampleDistance); + bool headRayHit = Physics.Raycast(headRay, out headHit, raySampleDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + bool eyeRayHit = Physics.Raycast(eyeRay, raySampleDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); //Debug.LogFormat("Ray contact: HeadRay: {0}, EyeRay {1}", headRayHit, eyeRayHit); @@ -155,4 +156,4 @@ void HeadDipHandling() } } } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Game/Player/HangingMotor.cs b/Assets/Scripts/Game/Player/HangingMotor.cs index 168d00b8c1..f1e7a614c2 100644 --- a/Assets/Scripts/Game/Player/HangingMotor.cs +++ b/Assets/Scripts/Game/Player/HangingMotor.cs @@ -1,5 +1,6 @@ using System; using UnityEngine; +using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Game { @@ -191,7 +192,7 @@ private bool HangingTransition(HangingTransitionState transState) private void HangMoveDirection() { RaycastHit hit; - if (Physics.SphereCast(controller.transform.position, scanner.HeadHitRadius, controller.transform.up, out hit, 2f)) + if (Physics.SphereCast(controller.transform.position, scanner.HeadHitRadius, controller.transform.up, out hit, 2f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { float playerspeed = speedChanger.GetClimbingSpeed(playerMotor.Speed); Vector3 moveVector = Vector3.zero; diff --git a/Assets/Scripts/Game/Player/PlayerHeightChanger.cs b/Assets/Scripts/Game/Player/PlayerHeightChanger.cs index 7231186f84..d6e3b06cce 100644 --- a/Assets/Scripts/Game/Player/PlayerHeightChanger.cs +++ b/Assets/Scripts/Game/Player/PlayerHeightChanger.cs @@ -10,6 +10,7 @@ // using DaggerfallWorkshop.Game.Serialization; +using DaggerfallWorkshop.Game.Utility; using UnityEngine; using System; @@ -527,7 +528,7 @@ private bool CanStand() float distance = camCrouchToStandDist; Ray ray = new Ray(controller.transform.position, Vector3.up); - return !Physics.SphereCast(ray, controller.radius, distance); + return !Physics.SphereCast(ray, controller.radius, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); } #endregion diff --git a/Assets/Scripts/Game/Player/PlayerMoveScanner.cs b/Assets/Scripts/Game/Player/PlayerMoveScanner.cs index 3b6502f2b6..1c85124ef5 100644 --- a/Assets/Scripts/Game/Player/PlayerMoveScanner.cs +++ b/Assets/Scripts/Game/Player/PlayerMoveScanner.cs @@ -16,6 +16,7 @@ using DaggerfallWorkshop.Game.Serialization; using DaggerfallWorkshop.Game.UserInterfaceWindows; using DaggerfallWorkshop.Game.Entity; +using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Game { @@ -161,7 +162,7 @@ public void FindStep(Vector3 moveDirection) RaycastHit hit; - if (!acrobatMotor.Jumping && Physics.SphereCast(checkStepRay, 0.1f, out hit, maxRange)) + if (!acrobatMotor.Jumping && Physics.SphereCast(checkStepRay, 0.1f, out hit, maxRange, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) StepHitDistance = hit.distance; else StepHitDistance = 0f; @@ -171,7 +172,7 @@ public bool FindHeadHit(Ray ray) { //Ray ray = new Ray(controller.transform.position, Vector3.up); RaycastHit hit = new RaycastHit(); - if (Physics.SphereCast(ray, HeadHitRadius, out hit, 2f)) + if (Physics.SphereCast(ray, HeadHitRadius, out hit, 2f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { if (hit.collider.GetComponent()) { @@ -223,7 +224,7 @@ public void FindAdjacentSurface(Vector3 origin, Vector3 direction, RotationDirec // use recursion to raycast vectors to find the adjacent wall Debug.DrawRay(origin, direction, Color.green, Time.deltaTime); - if (Physics.Raycast(origin, direction, out hit, distance) + if (Physics.Raycast(origin, direction, out hit, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap) && (hit.collider.gameObject.GetComponent() != null)) { // normal vector of raycasthit @@ -314,7 +315,7 @@ public void SetHitSomethingInFront() else inFrontDirection = controller.transform.forward; - HitSomethingInFront = (Physics.Raycast(controller.transform.position, inFrontDirection, out hit, controller.radius + 0.1f)); + HitSomethingInFront = (Physics.Raycast(controller.transform.position, inFrontDirection, out hit, controller.radius + 0.1f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)); } public void ResetAdjacentSurfaces() @@ -326,4 +327,4 @@ public void ResetAdjacentSurfaces() FrontUnderCeiling = null; } } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Game/PlayerActivate.cs b/Assets/Scripts/Game/PlayerActivate.cs index dbb7afba5b..7f3818dd96 100644 --- a/Assets/Scripts/Game/PlayerActivate.cs +++ b/Assets/Scripts/Game/PlayerActivate.cs @@ -20,10 +20,10 @@ using DaggerfallWorkshop.Game.Items; using DaggerfallWorkshop.Game.Banking; using DaggerfallWorkshop.Game.Guilds; +using DaggerfallWorkshop.Game.Utility; using DaggerfallWorkshop.Game.MagicAndEffects.MagicEffects; using System.Collections.Generic; using DaggerfallWorkshop.Utility.AssetInjection; -using DaggerfallWorkshop.Game.Utility; using DaggerfallWorkshop.Game.Formulas; using DaggerfallWorkshop.Game.Utility.ModSupport; using DaggerfallWorkshop.Localization; @@ -209,7 +209,7 @@ void Start() playerGPS = GetComponent(); playerEnterExit = GetComponent(); mainCamera = GameManager.Instance.MainCamera; - playerLayerMask = ~(1 << LayerMask.NameToLayer("Player")); + playerLayerMask = ~(1 << LayerMask.NameToLayer("Player") | 1 << LayerMask.NameToLayer("Automap")); } void Update() diff --git a/Assets/Scripts/Game/PlayerEnterExit.cs b/Assets/Scripts/Game/PlayerEnterExit.cs index 045e462f1d..6d17560415 100644 --- a/Assets/Scripts/Game/PlayerEnterExit.cs +++ b/Assets/Scripts/Game/PlayerEnterExit.cs @@ -17,6 +17,7 @@ using DaggerfallConnect; using DaggerfallConnect.Arena2; using DaggerfallConnect.Utility; +using DaggerfallWorkshop.Game.Utility; using DaggerfallWorkshop.Game.Serialization; using DaggerfallWorkshop.Game.UserInterfaceWindows; using DaggerfallWorkshop.Game.Entity; @@ -1242,7 +1243,7 @@ private void SetStanding() // Snap player to ground RaycastHit hit; Ray ray = new Ray(transform.position, Vector3.down); - if (Physics.Raycast(ray, out hit, PlayerHeightChanger.controllerStandingHeight * 2f)) + if (Physics.Raycast(ray, out hit, PlayerHeightChanger.controllerStandingHeight * 2f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { // Clear falling damage so player doesn't take damage if they transitioned into a dungeon while jumping GameManager.Instance.AcrobatMotor.ClearFallingDamage(); diff --git a/Assets/Scripts/Game/PlayerMotor.cs b/Assets/Scripts/Game/PlayerMotor.cs index 72e086f3c9..35ecb284f7 100644 --- a/Assets/Scripts/Game/PlayerMotor.cs +++ b/Assets/Scripts/Game/PlayerMotor.cs @@ -190,7 +190,7 @@ public bool StartRestGroundedCheck() // Collision fix for when player is levitating but feet are "close enough" to ground to rest // This is required as controller physics requires movement to process grounded collision normally Ray ray = new Ray(transform.position, Vector3.down); - return (Physics.Raycast(ray, controller.height / 2 + 0.2f)); + return (Physics.Raycast(ray, controller.height / 2 + 0.2f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)); } /// @@ -427,7 +427,7 @@ public Vector3 FindGroundPosition(float distance = 10) { RaycastHit hit; Ray ray = new Ray(transform.position, Vector3.down); - if (Physics.Raycast(ray, out hit, distance)) + if (Physics.Raycast(ray, out hit, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return hit.point; return transform.position; @@ -438,7 +438,7 @@ public bool FixStanding(float extraHeight = 0, float extraDistance = 0) { RaycastHit hit; Ray ray = new Ray(transform.position + (Vector3.up * extraHeight), Vector3.down); - if (Physics.Raycast(ray, out hit, (controller.height * 2) + extraHeight + extraDistance)) + if (Physics.Raycast(ray, out hit, (controller.height * 2) + extraHeight + extraDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { // Position player at hit position plus just over half controller height up transform.position = hit.point + Vector3.up * (controller.height * 0.65f); @@ -508,7 +508,7 @@ bool GetOnExteriorGroundMethod() // Must be outside and actually be standing on a terrain object not some other object (e.g. player ship) RaycastHit hit; - if (GameManager.Instance.PlayerEnterExit.IsPlayerInside || !Physics.Raycast(transform.position, Vector3.down, out hit, rayDistance * 2)) + if (GameManager.Instance.PlayerEnterExit.IsPlayerInside || !Physics.Raycast(transform.position, Vector3.down, out hit, rayDistance * 2, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { return false; } @@ -534,7 +534,7 @@ bool GetOnExteriorStaticGeometryMethod() // Must be outside and actually be standing on a terrain object not some other object (e.g. player ship) RaycastHit hit; - if (GameManager.Instance.PlayerEnterExit.IsPlayerInside || !Physics.Raycast(transform.position, Vector3.down, out hit, rayDistance * 2)) + if (GameManager.Instance.PlayerEnterExit.IsPlayerInside || !Physics.Raycast(transform.position, Vector3.down, out hit, rayDistance * 2, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { return false; } diff --git a/Assets/Scripts/Game/Questing/Actions/CreateFoe.cs b/Assets/Scripts/Game/Questing/Actions/CreateFoe.cs index 1f4c591cf7..944d0f2650 100644 --- a/Assets/Scripts/Game/Questing/Actions/CreateFoe.cs +++ b/Assets/Scripts/Game/Questing/Actions/CreateFoe.cs @@ -288,7 +288,7 @@ void PlaceFoeFreely(GameObject[] gameObjects, Transform parent, float minDistanc // Check for a hit Vector3 currentPoint; RaycastHit initialHit; - if (Physics.Raycast(ray, out initialHit, maxDistance)) + if (Physics.Raycast(ray, out initialHit, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { float cos_normal = Vector3.Dot(- spawnDirection, initialHit.normal.normalized); if (cos_normal < 1e-6) @@ -313,12 +313,12 @@ void PlaceFoeFreely(GameObject[] gameObjects, Transform parent, float minDistanc // Must be able to find a surface below RaycastHit floorHit; ray = new Ray(currentPoint, Vector3.down); - if (!Physics.Raycast(ray, out floorHit, maxFloorDistance)) + if (!Physics.Raycast(ray, out floorHit, maxFloorDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return; // Ensure this is open space Vector3 testPoint = floorHit.point + Vector3.up * separationDistance; - Collider[] colliders = Physics.OverlapSphere(testPoint, overlapSphereRadius); + Collider[] colliders = Physics.OverlapSphere(testPoint, overlapSphereRadius, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); if (colliders.Length > 0) return; @@ -431,4 +431,4 @@ public override void RestoreSaveData(object dataIn) #endregion } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Game/Utility/FoeSpawner.cs b/Assets/Scripts/Game/Utility/FoeSpawner.cs index b865b8006f..f4cb8cda10 100644 --- a/Assets/Scripts/Game/Utility/FoeSpawner.cs +++ b/Assets/Scripts/Game/Utility/FoeSpawner.cs @@ -163,7 +163,7 @@ void PlaceFoeFreely(GameObject[] gameObjects, float minDistance = 5f, float maxD // Check for a hit Vector3 currentPoint; RaycastHit initialHit; - if (Physics.Raycast(ray, out initialHit, maxDistance)) + if (Physics.Raycast(ray, out initialHit, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { float cos_normal = Vector3.Dot(-spawnDirection, initialHit.normal.normalized); if (cos_normal < 1e-6) @@ -188,12 +188,12 @@ void PlaceFoeFreely(GameObject[] gameObjects, float minDistance = 5f, float maxD // Must be able to find a surface below RaycastHit floorHit; ray = new Ray(currentPoint, Vector3.down); - if (!Physics.Raycast(ray, out floorHit, maxFloorDistance)) + if (!Physics.Raycast(ray, out floorHit, maxFloorDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return; // Ensure this is open space Vector3 testPoint = floorHit.point + Vector3.up * separationDistance; - Collider[] colliders = Physics.OverlapSphere(testPoint, overlapSphereRadius); + Collider[] colliders = Physics.OverlapSphere(testPoint, overlapSphereRadius, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); if (colliders.Length > 0) return; @@ -241,4 +241,4 @@ void DestroyOldFoeGameObjects(GameObject[] gameObjects) #endregion } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Game/Utility/PhysicsLayers.cs b/Assets/Scripts/Game/Utility/PhysicsLayers.cs new file mode 100644 index 0000000000..424393b3e1 --- /dev/null +++ b/Assets/Scripts/Game/Utility/PhysicsLayers.cs @@ -0,0 +1,26 @@ +// Project: Daggerfall Unity +// Copyright: Copyright (C) 2009-2023 Daggerfall Workshop +// Web Site: http://www.dfworkshop.net +// License: MIT License (http://www.opensource.org/licenses/mit-license.php) +// Source Code: https://github.com/Interkarma/daggerfall-unity +// Original Author: Gavin Clayton (interkarma@dfworkshop.net) +// Contributors: +// +// Notes: +// + +using UnityEngine; + +namespace DaggerfallWorkshop.Game.Utility +{ + /// + /// Shared physics layer masks. + /// + public static class PhysicsLayers + { + public static int DefaultRaycastLayersWithoutAutomap + { + get { return Physics.DefaultRaycastLayers & ~(1 << LayerMask.NameToLayer("Automap")); } + } + } +} diff --git a/Assets/Scripts/Game/Utility/PhysicsLayers.cs.meta b/Assets/Scripts/Game/Utility/PhysicsLayers.cs.meta new file mode 100644 index 0000000000..e7f7a6fbd3 --- /dev/null +++ b/Assets/Scripts/Game/Utility/PhysicsLayers.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d413ee3330123e8498e671b7d20b13e2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Game/WeaponManager.cs b/Assets/Scripts/Game/WeaponManager.cs index f26f276ad6..369dea35f8 100644 --- a/Assets/Scripts/Game/WeaponManager.cs +++ b/Assets/Scripts/Game/WeaponManager.cs @@ -196,7 +196,7 @@ void Start() //weaponSensitivity = DaggerfallUnity.Settings.WeaponSensitivity; mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); player = transform.gameObject; - playerLayerMask = ~(1 << LayerMask.NameToLayer("Player")); + playerLayerMask = ~(1 << LayerMask.NameToLayer("Player") | 1 << LayerMask.NameToLayer("Automap")); _gesture = new Gesture(); _longestDim = Math.Max(Screen.width, Screen.height); SetMelee(ScreenWeapon); diff --git a/Assets/Scripts/Terrain/StreamingWorld.cs b/Assets/Scripts/Terrain/StreamingWorld.cs index 37f14a7fc5..5fac671981 100644 --- a/Assets/Scripts/Terrain/StreamingWorld.cs +++ b/Assets/Scripts/Terrain/StreamingWorld.cs @@ -1598,7 +1598,7 @@ private bool FixStanding(Transform playerTransform, float playerHeight, float ex { RaycastHit hit; Ray ray = new Ray(playerTransform.position + (Vector3.up * extraHeight), Vector3.down); - if (Physics.Raycast(ray, out hit, (playerHeight * 2) + extraHeight + extraDistance)) + if (Physics.Raycast(ray, out hit, (playerHeight * 2) + extraHeight + extraDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { // Position player at hit position plus just over half controller height up playerTransform.position = hit.point + Vector3.up * (playerHeight * 0.6f); @@ -1858,4 +1858,4 @@ protected virtual void RaiseOnFloatingOriginChangeEvent() #endregion } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Utility/AssetInjection/Components/FaceWall.cs b/Assets/Scripts/Utility/AssetInjection/Components/FaceWall.cs index 0563c59769..b47f6df9ec 100644 --- a/Assets/Scripts/Utility/AssetInjection/Components/FaceWall.cs +++ b/Assets/Scripts/Utility/AssetInjection/Components/FaceWall.cs @@ -12,6 +12,7 @@ using System; using UnityEngine; using UnityEngine.Serialization; +using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Utility.AssetInjection { @@ -100,7 +101,7 @@ private void Start() private bool HitWall(Vector3 direction) { Vector3 worldSpaceDirection = transform.TransformDirection(direction); - return Physics.Raycast(gameObject.transform.position, worldSpaceDirection, MaxDistance); + return Physics.Raycast(gameObject.transform.position, worldSpaceDirection, MaxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); } /// @@ -109,7 +110,7 @@ private bool HitWall(Vector3 direction) private void Move() { RaycastHit hitInfo; - if (Physics.Raycast(new Ray(transform.position, transform.forward), out hitInfo, MaxDistance)) + if (Physics.Raycast(new Ray(transform.position, transform.forward), out hitInfo, MaxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) { Bounds bounds = meshRenderer.bounds; @@ -133,14 +134,14 @@ private void Align() Vector3 bottomPoint = gameObject.transform.position; bottomPoint.y = bounds.min.y; RaycastHit hitInfoBottom; - if (!Physics.Raycast(new Ray(bottomPoint, transform.forward), out hitInfoBottom, MaxDistance)) + if (!Physics.Raycast(new Ray(bottomPoint, transform.forward), out hitInfoBottom, MaxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return; // Top point on bounds Vector3 topPoint = gameObject.transform.position; topPoint.y = bounds.max.y; RaycastHit hitInfoTop; - if (!Physics.Raycast(new Ray(topPoint, transform.forward), out hitInfoTop, MaxDistance)) + if (!Physics.Raycast(new Ray(topPoint, transform.forward), out hitInfoTop, MaxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return; // Calculate angle and rotate @@ -151,4 +152,4 @@ private void Align() #endregion } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Utility/AssetInjection/Components/NPCModelRotator.cs b/Assets/Scripts/Utility/AssetInjection/Components/NPCModelRotator.cs index abb171f220..36a6a21890 100644 --- a/Assets/Scripts/Utility/AssetInjection/Components/NPCModelRotator.cs +++ b/Assets/Scripts/Utility/AssetInjection/Components/NPCModelRotator.cs @@ -10,6 +10,7 @@ // using DaggerfallWorkshop.Game; +using DaggerfallWorkshop.Game.Utility; using UnityEngine; namespace DaggerfallWorkshop.Utility.AssetInjection @@ -53,7 +54,7 @@ private void Start() { closestDoorDistance = Vector3.Distance(transform.position, closestStaticDoorPos); - bool visible = !Physics.Raycast(transform.position, closestStaticDoorPos - transform.position, closestDoorDistance - 0.5f); + bool visible = !Physics.Raycast(transform.position, closestStaticDoorPos - transform.position, closestDoorDistance - 0.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); if (visible) closestDoorVisible = true; } @@ -66,7 +67,7 @@ private void Start() //Debug.LogFormat("Door at {0}, centre {1} rot {2}", actionDoors[i].transform.position, doorCentre, actionDoors[i].transform.rotation); float distance = Vector3.Distance(transform.position, doorCentre); - bool visible = !Physics.Raycast(transform.position, doorCentre - transform.position, distance - 0.5f); + bool visible = !Physics.Raycast(transform.position, doorCentre - transform.position, distance - 0.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); if (visible) { diff --git a/Assets/Scripts/Utility/AssetInjection/Components/ObjectPositioner.cs b/Assets/Scripts/Utility/AssetInjection/Components/ObjectPositioner.cs index 279e66251b..c01010e779 100644 --- a/Assets/Scripts/Utility/AssetInjection/Components/ObjectPositioner.cs +++ b/Assets/Scripts/Utility/AssetInjection/Components/ObjectPositioner.cs @@ -12,6 +12,7 @@ // #define TEST_TRANSLATION using UnityEngine; +using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Utility.AssetInjection { @@ -128,7 +129,7 @@ protected void Move(Vector3 direction) Ray ray = new Ray(bounds.center, transform.TransformDirection(direction)); RaycastHit hitInfo; - if (!Physics.Raycast(ray, out hitInfo, maxDistance)) + if (!Physics.Raycast(ray, out hitInfo, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return; // Get the bound extent on the direction of the ray axis @@ -164,4 +165,4 @@ private static Vector3 GetDirection(Direction direction) Vector3.zero; } } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Utility/AssetInjection/Components/WallPropPositioner.cs b/Assets/Scripts/Utility/AssetInjection/Components/WallPropPositioner.cs index cb6f2cf388..f4aaf3138e 100644 --- a/Assets/Scripts/Utility/AssetInjection/Components/WallPropPositioner.cs +++ b/Assets/Scripts/Utility/AssetInjection/Components/WallPropPositioner.cs @@ -10,6 +10,7 @@ // using UnityEngine; +using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Utility.AssetInjection { @@ -78,14 +79,14 @@ protected void Align(Vector3 direction) Vector3 bottomPoint = gameObject.transform.position; bottomPoint.y = bounds.min.y; RaycastHit hitInfoBottom; - if (!Physics.Raycast(new Ray(bottomPoint, worldSpaceDirection), out hitInfoBottom, maxDistance)) + if (!Physics.Raycast(new Ray(bottomPoint, worldSpaceDirection), out hitInfoBottom, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return; // Top point on bounds Vector3 topPoint = gameObject.transform.position; topPoint.y = bounds.max.y; RaycastHit hitInfoTop; - if (!Physics.Raycast(new Ray(topPoint, worldSpaceDirection), out hitInfoTop, maxDistance)) + if (!Physics.Raycast(new Ray(topPoint, worldSpaceDirection), out hitInfoTop, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return; // Calculate delta @@ -107,7 +108,7 @@ protected void Align(Vector3 direction) private bool HitWall(Vector3 direction) { Vector3 worldSpaceDirection = transform.TransformDirection(direction); - return Physics.Raycast(gameObject.transform.position, worldSpaceDirection, maxDistance); + return Physics.Raycast(gameObject.transform.position, worldSpaceDirection, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); } } } diff --git a/Assets/Scripts/Utility/GameObjectHelper.cs b/Assets/Scripts/Utility/GameObjectHelper.cs index 34cd5345ca..48e54fe07f 100644 --- a/Assets/Scripts/Utility/GameObjectHelper.cs +++ b/Assets/Scripts/Utility/GameObjectHelper.cs @@ -338,7 +338,7 @@ public static void AlignBillboardToGround(GameObject go, Vector2 size, float dis // Cast ray down to find ground below RaycastHit hit; Ray ray = new Ray(go.transform.position + new Vector3(0, 0.2f, 0), Vector3.down); - if (!Physics.Raycast(ray, out hit, distance)) + if (!Physics.Raycast(ray, out hit, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return; // Position bottom just above ground by adjusting parent gameobject @@ -354,7 +354,7 @@ public static void AlignControllerToGround(CharacterController controller, float // Cast ray down from slightly above midpoint to find ground below RaycastHit hit; Ray ray = new Ray(controller.transform.position + new Vector3(0, 0.2f, 0), Vector3.down); - if (!Physics.Raycast(ray, out hit, distance)) + if (!Physics.Raycast(ray, out hit, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) return; // Position bottom just above ground by adjusting parent gameobject @@ -1522,4 +1522,4 @@ public static Quaternion QuaternionFromMatrix(Matrix4x4 m) return q; } } -} \ No newline at end of file +} From 5826e162c77d2c182226621504121676a97e5d6d Mon Sep 17 00:00:00 2001 From: Vivian V Wing Date: Sun, 7 Jun 2026 23:43:21 -0700 Subject: [PATCH 3/5] Undid changes that conflict with PR 2781 #2781 already ignores the Automap layer in DaggerfallMissile and WeaponManager --- Assets/Scripts/Game/DaggerfallMissile.cs | 4 ++-- Assets/Scripts/Game/WeaponManager.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Game/DaggerfallMissile.cs b/Assets/Scripts/Game/DaggerfallMissile.cs index 415cb69e91..b5c8728e13 100644 --- a/Assets/Scripts/Game/DaggerfallMissile.cs +++ b/Assets/Scripts/Game/DaggerfallMissile.cs @@ -396,7 +396,7 @@ public static DaggerfallEntityBehaviour GetEntityTargetInTouchRange(Vector3 aimP RaycastHit hit; aimPosition -= aimDirection * 0.1f; Ray ray = new Ray(aimPosition, aimDirection); - if (Physics.SphereCast(ray, SphereCastRadius, out hit, TouchRange, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.SphereCast(ray, SphereCastRadius, out hit, TouchRange)) return hit.transform.GetComponent(); else return null; @@ -444,7 +444,7 @@ void DoAreaOfEffect(Vector3 position, bool ignoreCaster = false) transform.position = position; // Collect AOE targets and ignore duplicates - Collider[] overlaps = Physics.OverlapSphere(position, ExplosionRadius, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + Collider[] overlaps = Physics.OverlapSphere(position, ExplosionRadius); for (int i = 0; i < overlaps.Length; i++) { DaggerfallEntityBehaviour aoeEntity = overlaps[i].GetComponent(); diff --git a/Assets/Scripts/Game/WeaponManager.cs b/Assets/Scripts/Game/WeaponManager.cs index 369dea35f8..f26f276ad6 100644 --- a/Assets/Scripts/Game/WeaponManager.cs +++ b/Assets/Scripts/Game/WeaponManager.cs @@ -196,7 +196,7 @@ void Start() //weaponSensitivity = DaggerfallUnity.Settings.WeaponSensitivity; mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); player = transform.gameObject; - playerLayerMask = ~(1 << LayerMask.NameToLayer("Player") | 1 << LayerMask.NameToLayer("Automap")); + playerLayerMask = ~(1 << LayerMask.NameToLayer("Player")); _gesture = new Gesture(); _longestDim = Math.Max(Screen.width, Screen.height); SetMelee(ScreenWeapon); From ff59bc3c61d3524d62629b39da633beb83e1486c Mon Sep 17 00:00:00 2001 From: Vivian V Wing Date: Tue, 9 Jun 2026 21:40:31 -0700 Subject: [PATCH 4/5] Reverted changes to raycasts --- .../Game/Addons/RmbBlockEditor/Placeholder.cs | 5 ++-- .../Console/Scripts/DefaultCommands.cs | 9 +++---- .../WorldDataEditor/Editor/WorldDataEditor.cs | 3 +-- Assets/Scripts/Game/DaggerfallMissile.cs | 1 - Assets/Scripts/Game/EnemyMotor.cs | 11 ++++---- Assets/Scripts/Game/EnemySenses.cs | 6 ++--- Assets/Scripts/Game/EnemySounds.cs | 5 ++-- Assets/Scripts/Game/Entities/PlayerEntity.cs | 2 +- Assets/Scripts/Game/MobilePersonMotor.cs | 4 +-- Assets/Scripts/Game/Player/ClimbingMotor.cs | 8 +++--- Assets/Scripts/Game/Player/FrictionMotor.cs | 11 ++++---- Assets/Scripts/Game/Player/HangingMotor.cs | 3 +-- .../Game/Player/PlayerHeightChanger.cs | 3 +-- .../Scripts/Game/Player/PlayerMoveScanner.cs | 11 ++++---- Assets/Scripts/Game/PlayerActivate.cs | 4 +-- Assets/Scripts/Game/PlayerEnterExit.cs | 3 +-- Assets/Scripts/Game/PlayerMotor.cs | 10 +++---- .../Game/Questing/Actions/CreateFoe.cs | 8 +++--- Assets/Scripts/Game/Utility/FoeSpawner.cs | 8 +++--- Assets/Scripts/Game/Utility/PhysicsLayers.cs | 26 ------------------- .../Game/Utility/PhysicsLayers.cs.meta | 11 -------- Assets/Scripts/Terrain/StreamingWorld.cs | 4 +-- .../AssetInjection/Components/FaceWall.cs | 11 ++++---- .../Components/NPCModelRotator.cs | 5 ++-- .../Components/ObjectPositioner.cs | 5 ++-- .../Components/WallPropPositioner.cs | 7 +++-- Assets/Scripts/Utility/GameObjectHelper.cs | 6 ++--- 27 files changed, 69 insertions(+), 121 deletions(-) delete mode 100644 Assets/Scripts/Game/Utility/PhysicsLayers.cs delete mode 100644 Assets/Scripts/Game/Utility/PhysicsLayers.cs.meta diff --git a/Assets/Game/Addons/RmbBlockEditor/Placeholder.cs b/Assets/Game/Addons/RmbBlockEditor/Placeholder.cs index e57387a66d..92100e080c 100644 --- a/Assets/Game/Addons/RmbBlockEditor/Placeholder.cs +++ b/Assets/Game/Addons/RmbBlockEditor/Placeholder.cs @@ -7,7 +7,6 @@ using System; using DaggerfallConnect.Arena2; -using DaggerfallWorkshop.Game.Utility; using UnityEditor; using UnityEngine; @@ -85,7 +84,7 @@ protected void OnSceneGUI(SceneView sceneView) Vector3 mousePosition = Event.current.mousePosition; Ray ray = HandleUtility.GUIPointToWorldRay(mousePosition); - if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap) && !mouseHasDragged) + if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity) && !mouseHasDragged) { OnRaycastHit(hit); } @@ -352,4 +351,4 @@ protected override void OnRaycastHit(RaycastHit hit) } } #endif -} +} \ No newline at end of file diff --git a/Assets/Game/Addons/UnityConsole/Console/Scripts/DefaultCommands.cs b/Assets/Game/Addons/UnityConsole/Console/Scripts/DefaultCommands.cs index 52c51c2264..d675df1149 100644 --- a/Assets/Game/Addons/UnityConsole/Console/Scripts/DefaultCommands.cs +++ b/Assets/Game/Addons/UnityConsole/Console/Scripts/DefaultCommands.cs @@ -19,7 +19,6 @@ using DaggerfallWorkshop.Game.Formulas; using DaggerfallConnect; using DaggerfallWorkshop.Game.Serialization; -using DaggerfallWorkshop.Game.Utility; using DaggerfallWorkshop.Utility.AssetInjection; using DaggerfallConnect.FallExe; using DaggerfallWorkshop.Game.Utility.ModSupport; @@ -1522,7 +1521,7 @@ public static string Execute(params string[] args) DaggerfallActionDoor door; RaycastHit hitInfo; Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); - if (!(Physics.Raycast(ray, out hitInfo, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))) + if (!(Physics.Raycast(ray, out hitInfo))) return error; else { @@ -1551,7 +1550,7 @@ public static string Execute(params string[] args) DaggerfallAction action; RaycastHit hitInfo; Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); - if (!(Physics.Raycast(ray, out hitInfo, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))) + if (!(Physics.Raycast(ray, out hitInfo))) return error; else { @@ -1673,7 +1672,7 @@ public static string Execute(params string[] args) Vector3 origin = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); Ray ray = new Ray(origin + Camera.main.transform.forward * .2f, Camera.main.transform.forward); GameManager.Instance.AcrobatMotor.ClearFallingDamage(); - if (!(Physics.Raycast(ray, out hitInfo, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))) + if (!(Physics.Raycast(ray, out hitInfo, maxDistance))) { Console.Log("Didn't hit anything..."); if (forceTeleOnNoHit) @@ -2172,7 +2171,7 @@ public static string Execute(params string[] args) Vector3 origin = frictionMotor.ContactPoint; origin.y += cc.height; Ray ray = new Ray(origin, Vector3.down); - if (!(Physics.Raycast(ray, out hitInfo, cc.height * 2, PhysicsLayers.DefaultRaycastLayersWithoutAutomap))) + if (!(Physics.Raycast(ray, out hitInfo, cc.height * 2))) { return "Failed to reposition - try Teleport or if inside tele2exit"; } diff --git a/Assets/Game/Addons/WorldDataEditor/Editor/WorldDataEditor.cs b/Assets/Game/Addons/WorldDataEditor/Editor/WorldDataEditor.cs index 70a6bfbab2..a483235ccc 100644 --- a/Assets/Game/Addons/WorldDataEditor/Editor/WorldDataEditor.cs +++ b/Assets/Game/Addons/WorldDataEditor/Editor/WorldDataEditor.cs @@ -14,7 +14,6 @@ using DaggerfallConnect.Arena2; using DaggerfallWorkshop.Utility.AssetInjection; using DaggerfallWorkshop.Utility; -using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Game.Utility.WorldDataEditor { @@ -925,7 +924,7 @@ private void AddItemWindow() // Try to position where the camera is looking Ray newRay = new Ray(SceneView.lastActiveSceneView.camera.transform.position, SceneView.lastActiveSceneView.camera.transform.forward); RaycastHit hit = new RaycastHit(); - if (Physics.Raycast(newRay, out hit, 200, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(newRay, out hit, 200)) go.transform.position = hit.point; else go.transform.position = SceneView.lastActiveSceneView.camera.transform.position + (SceneView.lastActiveSceneView.camera.transform.forward * 10); diff --git a/Assets/Scripts/Game/DaggerfallMissile.cs b/Assets/Scripts/Game/DaggerfallMissile.cs index b5c8728e13..e19184f823 100644 --- a/Assets/Scripts/Game/DaggerfallMissile.cs +++ b/Assets/Scripts/Game/DaggerfallMissile.cs @@ -14,7 +14,6 @@ using DaggerfallWorkshop.Utility; using DaggerfallWorkshop.Game.MagicAndEffects; using DaggerfallWorkshop.Game.Entity; -using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Game { diff --git a/Assets/Scripts/Game/EnemyMotor.cs b/Assets/Scripts/Game/EnemyMotor.cs index cdc2666000..528c1c67be 100644 --- a/Assets/Scripts/Game/EnemyMotor.cs +++ b/Assets/Scripts/Game/EnemyMotor.cs @@ -12,7 +12,6 @@ using UnityEngine; using DaggerfallWorkshop.Game.Entity; using DaggerfallWorkshop.Game.MagicAndEffects; -using DaggerfallWorkshop.Game.Utility; using System.Collections.Generic; using DaggerfallWorkshop.Utility; using System.Linq; @@ -138,10 +137,10 @@ void Start() (mobile.Enemy.HasRangedAttack1 && (!mobile.Enemy.CastsMagic || mobile.Enemy.HasRangedAttack2)); // Add things AI should ignore when checking for a clear path to shoot. - ignoreMaskForShooting = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast") | 1 << LayerMask.NameToLayer("Automap")); + ignoreMaskForShooting = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast")); // Also ignore arrows and "Ignore Raycast" layer for obstacles - ignoreMaskForObstacles = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast") | 1 << LayerMask.NameToLayer("Automap")); + ignoreMaskForObstacles = ~(1 << LayerMask.NameToLayer("SpellMissiles") | 1 << LayerMask.NameToLayer("Ignore Raycast")); LastGroundedY = transform.position.y; @@ -223,7 +222,7 @@ public Vector3 FindGroundPosition(float distance = 16) { RaycastHit hit; Ray ray = new Ray(transform.position, Vector3.down); - if (Physics.Raycast(ray, out hit, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(ray, out hit, distance)) return hit.point; return transform.position; @@ -1189,7 +1188,7 @@ void ObstacleCheck(Vector3 direction) p1 = transform.position + (Vector3.up * -originalHeight * 0.25f); p2 = p1 + (Vector3.up * originalHeight * 0.75f); - if (!Physics.CapsuleCast(p1, p2, controller.radius / 2, direction, checkDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!Physics.CapsuleCast(p1, p2, controller.radius / 2, direction, checkDistance)) { ObstacleDetected = false; foundUpwardSlope = true; @@ -1217,7 +1216,7 @@ void FallCheck(Vector3 direction) Ray ray = new Ray(rayOrigin + direction, Vector3.down); RaycastHit hit; - fallDetected = !Physics.Raycast(ray, out hit, (originalHeight * 0.5f) + 1.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + fallDetected = !Physics.Raycast(ray, out hit, (originalHeight * 0.5f) + 1.5f); } /// diff --git a/Assets/Scripts/Game/EnemySenses.cs b/Assets/Scripts/Game/EnemySenses.cs index 0468af5462..a2fcd18daa 100644 --- a/Assets/Scripts/Game/EnemySenses.cs +++ b/Assets/Scripts/Game/EnemySenses.cs @@ -550,7 +550,7 @@ public Vector3 PredictNextTargetPos(float interceptSpeed) // If aware of target, if distance is too far or can see nothing is there, use last known position as assumed current position if (targetInSight || targetInEarshot || (predictedTargetPos - transform.position).magnitude > SightRadius + mobile.Enemy.SightModifier - || !Physics.Raycast(transform.position, (predictedTargetPosWithoutLead - transform.position).normalized, out tempHit, SightRadius + mobile.Enemy.SightModifier, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + || !Physics.Raycast(transform.position, (predictedTargetPosWithoutLead - transform.position).normalized, out tempHit, SightRadius + mobile.Enemy.SightModifier)) { assumedCurrentPosition = lastKnownTargetPos; } @@ -605,7 +605,7 @@ public Vector3 PredictNextTargetPos(float interceptSpeed) // Don't predict target will move through obstacles (prevent predicting movement through walls) RaycastHit hit; Ray ray = new Ray(assumedCurrentPosition, (prediction - assumedCurrentPosition).normalized); - if (Physics.Raycast(ray, out hit, (prediction - assumedCurrentPosition).magnitude, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(ray, out hit, (prediction - assumedCurrentPosition).magnitude)) prediction = assumedCurrentPosition; } @@ -902,7 +902,7 @@ bool CanSeeTarget(DaggerfallEntityBehaviour target) Vector3 eyeDirectionToTarget = eyeToTarget.normalized; Ray ray = new Ray(eyePos, eyeDirectionToTarget); - if (Physics.Raycast(ray, out hit, SightRadius, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(ray, out hit, SightRadius)) { // Check if hit was target DaggerfallEntityBehaviour entity = hit.transform.gameObject.GetComponent(); diff --git a/Assets/Scripts/Game/EnemySounds.cs b/Assets/Scripts/Game/EnemySounds.cs index 7a79ee687d..f2fe46d159 100644 --- a/Assets/Scripts/Game/EnemySounds.cs +++ b/Assets/Scripts/Game/EnemySounds.cs @@ -13,7 +13,6 @@ using System.Collections; using DaggerfallWorkshop.Utility; using DaggerfallWorkshop.Game.Entity; -using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Game { @@ -236,7 +235,7 @@ private void SetVolumeScale() // Only checks when enemy plays attract sound, so not very expensive. RaycastHit hit; Ray ray = new Ray(transform.position, directionToPlayer); - if (Physics.Raycast(ray, out hit, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(ray, out hit)) { // Ignore player hit if (hit.transform.gameObject == player) @@ -253,4 +252,4 @@ private void SetVolumeScale() #endregion } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Game/Entities/PlayerEntity.cs b/Assets/Scripts/Game/Entities/PlayerEntity.cs index 408d57973f..3526852cef 100644 --- a/Assets/Scripts/Game/Entities/PlayerEntity.cs +++ b/Assets/Scripts/Game/Entities/PlayerEntity.cs @@ -715,7 +715,7 @@ public void SpawnCityGuards(bool immediateSpawn) // Check if npc sees player Vector3 eyeToTarget = playerEyePos - eyePos; Ray ray = new Ray(eyePos, eyeToTarget.normalized); - if (Physics.Raycast(ray, out hit, 77.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(ray, out hit, 77.5f)) { // Check if hit was player DaggerfallEntityBehaviour entity = hit.transform.gameObject.GetComponent(); diff --git a/Assets/Scripts/Game/MobilePersonMotor.cs b/Assets/Scripts/Game/MobilePersonMotor.cs index 069cc8ad0b..b337664001 100644 --- a/Assets/Scripts/Game/MobilePersonMotor.cs +++ b/Assets/Scripts/Game/MobilePersonMotor.cs @@ -416,7 +416,7 @@ bool IsDirectionClear(MobileDirection direction) // Aim low to better detect stairs tempTargetScenePosition.y += 0.1f; Ray ray = new Ray(transform.position, tempTargetScenePosition - transform.position); - bool collision = Physics.Raycast(transform.position, tempTargetScenePosition - transform.position, Vector3.Distance(transform.position, tempTargetScenePosition), ~mobileAsset.GetLayerMask() & ~(1 << LayerMask.NameToLayer("Automap"))); + bool collision = Physics.Raycast(transform.position, tempTargetScenePosition - transform.position, Vector3.Distance(transform.position, tempTargetScenePosition), ~mobileAsset.GetLayerMask()); // Debug.DrawRay(transform.position, tempTargetScenePosition - transform.position, collision ? Color.red : Color.green, 1f); return !collision; } @@ -545,4 +545,4 @@ private void FloatingOrigin_OnPositionUpdate(Vector3 offset) #endregion } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Game/Player/ClimbingMotor.cs b/Assets/Scripts/Game/Player/ClimbingMotor.cs index fc8e3200a9..2816a8628b 100644 --- a/Assets/Scripts/Game/Player/ClimbingMotor.cs +++ b/Assets/Scripts/Game/Player/ClimbingMotor.cs @@ -317,7 +317,7 @@ public void ClimbingCheck() // boolean that means ground directly below us is too close for climbing or rappelling bool tooCloseToGroundForClimb = (((isClimbing && (inputBack || isSlipping)) || airborneGraspWall) // short circuit evaluate the raycast, also prevents bug where you could teleport across town - && Physics.Raycast(controller.transform.position, Vector3.down, controller.height / 2 + 0.12f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)); + && Physics.Raycast(controller.transform.position, Vector3.down, controller.height / 2 + 0.12f)); CalcFrequencyAndToleranceOfWallChecks(airborneGraspWall); @@ -371,9 +371,9 @@ public void ClimbingCheck() // Test close to front of head for backward sloping wall like Scourg Barrow and bump a little backwards // Then slightly further back for short overhangs like eaves and bump more backwards and a little upwards // Height of raycast test is extended to help ensure there is clear space above not just an angled ceiling - if (!Physics.Raycast(frontTestPosition, Vector3.up, controller.height / 2 + 0.3f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!Physics.Raycast(frontTestPosition, Vector3.up, controller.height / 2 + 0.3f)) controller.transform.position += -wallDirection * 0.1f; - else if (!Physics.Raycast(backTestPosition, Vector3.up, controller.height / 2 + 0.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + else if (!Physics.Raycast(backTestPosition, Vector3.up, controller.height / 2 + 0.5f)) controller.transform.position += -wallDirection * 0.4f + Vector3.up * 0.3f; } @@ -588,7 +588,7 @@ private void GetClimbedWallInfo() wallDirection = -cornerNormalRay.direction; // Cast character controller shape forward to see if it is about to hit anything. Debug.DrawRay(controller.transform.position, wallDirection, Color.gray); - if (Physics.CapsuleCast(p1, p2, controller.radius, wallDirection, out hit, controller.radius + 0.1f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.CapsuleCast(p1, p2, controller.radius, wallDirection, out hit, controller.radius + 0.1f)) { // Immediately stop climbing if object not valid if (!IsClimable(hit.transform)) diff --git a/Assets/Scripts/Game/Player/FrictionMotor.cs b/Assets/Scripts/Game/Player/FrictionMotor.cs index 1eadefabb9..e735e1f92d 100644 --- a/Assets/Scripts/Game/Player/FrictionMotor.cs +++ b/Assets/Scripts/Game/Player/FrictionMotor.cs @@ -1,6 +1,5 @@ using DaggerfallConnect; using DaggerfallWorkshop.Game; -using DaggerfallWorkshop.Game.Utility; using DaggerfallWorkshop.Utility; using System.Collections; using System.Collections.Generic; @@ -100,7 +99,7 @@ private void SetSliding() sliding = false; // See if surface immediately below should be slid down. We use this normally rather than a ControllerColliderHit point, // because that interferes with step climbing amongst other annoyances - if (Physics.Raycast(myTransform.position, -Vector3.up, out hit, rayDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(myTransform.position, -Vector3.up, out hit, rayDistance)) { if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit) sliding = true; @@ -109,7 +108,7 @@ private void SetSliding() // So if the above raycast didn't catch anything, raycast down from the stored ControllerColliderHit point instead else { - Physics.Raycast(contactPoint + Vector3.up, -Vector3.up, out hit, Mathf.Infinity, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + Physics.Raycast(contactPoint + Vector3.up, -Vector3.up, out hit); if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit) sliding = true; } @@ -129,8 +128,8 @@ void HeadDipHandling() Ray headRay = new Ray(myTransform.position + new Vector3(0, heightChanger.FixedControllerStandingHeight / 2 + 0.25f, 0), myTransform.forward); Ray eyeRay = new Ray(GameManager.Instance.MainCamera.transform.position, myTransform.forward); RaycastHit headHit; - bool headRayHit = Physics.Raycast(headRay, out headHit, raySampleDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); - bool eyeRayHit = Physics.Raycast(eyeRay, raySampleDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + bool headRayHit = Physics.Raycast(headRay, out headHit, raySampleDistance); + bool eyeRayHit = Physics.Raycast(eyeRay, raySampleDistance); //Debug.LogFormat("Ray contact: HeadRay: {0}, EyeRay {1}", headRayHit, eyeRayHit); @@ -156,4 +155,4 @@ void HeadDipHandling() } } } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Game/Player/HangingMotor.cs b/Assets/Scripts/Game/Player/HangingMotor.cs index f1e7a614c2..168d00b8c1 100644 --- a/Assets/Scripts/Game/Player/HangingMotor.cs +++ b/Assets/Scripts/Game/Player/HangingMotor.cs @@ -1,6 +1,5 @@ using System; using UnityEngine; -using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Game { @@ -192,7 +191,7 @@ private bool HangingTransition(HangingTransitionState transState) private void HangMoveDirection() { RaycastHit hit; - if (Physics.SphereCast(controller.transform.position, scanner.HeadHitRadius, controller.transform.up, out hit, 2f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.SphereCast(controller.transform.position, scanner.HeadHitRadius, controller.transform.up, out hit, 2f)) { float playerspeed = speedChanger.GetClimbingSpeed(playerMotor.Speed); Vector3 moveVector = Vector3.zero; diff --git a/Assets/Scripts/Game/Player/PlayerHeightChanger.cs b/Assets/Scripts/Game/Player/PlayerHeightChanger.cs index d6e3b06cce..7231186f84 100644 --- a/Assets/Scripts/Game/Player/PlayerHeightChanger.cs +++ b/Assets/Scripts/Game/Player/PlayerHeightChanger.cs @@ -10,7 +10,6 @@ // using DaggerfallWorkshop.Game.Serialization; -using DaggerfallWorkshop.Game.Utility; using UnityEngine; using System; @@ -528,7 +527,7 @@ private bool CanStand() float distance = camCrouchToStandDist; Ray ray = new Ray(controller.transform.position, Vector3.up); - return !Physics.SphereCast(ray, controller.radius, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + return !Physics.SphereCast(ray, controller.radius, distance); } #endregion diff --git a/Assets/Scripts/Game/Player/PlayerMoveScanner.cs b/Assets/Scripts/Game/Player/PlayerMoveScanner.cs index 1c85124ef5..3b6502f2b6 100644 --- a/Assets/Scripts/Game/Player/PlayerMoveScanner.cs +++ b/Assets/Scripts/Game/Player/PlayerMoveScanner.cs @@ -16,7 +16,6 @@ using DaggerfallWorkshop.Game.Serialization; using DaggerfallWorkshop.Game.UserInterfaceWindows; using DaggerfallWorkshop.Game.Entity; -using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Game { @@ -162,7 +161,7 @@ public void FindStep(Vector3 moveDirection) RaycastHit hit; - if (!acrobatMotor.Jumping && Physics.SphereCast(checkStepRay, 0.1f, out hit, maxRange, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!acrobatMotor.Jumping && Physics.SphereCast(checkStepRay, 0.1f, out hit, maxRange)) StepHitDistance = hit.distance; else StepHitDistance = 0f; @@ -172,7 +171,7 @@ public bool FindHeadHit(Ray ray) { //Ray ray = new Ray(controller.transform.position, Vector3.up); RaycastHit hit = new RaycastHit(); - if (Physics.SphereCast(ray, HeadHitRadius, out hit, 2f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.SphereCast(ray, HeadHitRadius, out hit, 2f)) { if (hit.collider.GetComponent()) { @@ -224,7 +223,7 @@ public void FindAdjacentSurface(Vector3 origin, Vector3 direction, RotationDirec // use recursion to raycast vectors to find the adjacent wall Debug.DrawRay(origin, direction, Color.green, Time.deltaTime); - if (Physics.Raycast(origin, direction, out hit, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap) + if (Physics.Raycast(origin, direction, out hit, distance) && (hit.collider.gameObject.GetComponent() != null)) { // normal vector of raycasthit @@ -315,7 +314,7 @@ public void SetHitSomethingInFront() else inFrontDirection = controller.transform.forward; - HitSomethingInFront = (Physics.Raycast(controller.transform.position, inFrontDirection, out hit, controller.radius + 0.1f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)); + HitSomethingInFront = (Physics.Raycast(controller.transform.position, inFrontDirection, out hit, controller.radius + 0.1f)); } public void ResetAdjacentSurfaces() @@ -327,4 +326,4 @@ public void ResetAdjacentSurfaces() FrontUnderCeiling = null; } } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Game/PlayerActivate.cs b/Assets/Scripts/Game/PlayerActivate.cs index 7f3818dd96..dbb7afba5b 100644 --- a/Assets/Scripts/Game/PlayerActivate.cs +++ b/Assets/Scripts/Game/PlayerActivate.cs @@ -20,10 +20,10 @@ using DaggerfallWorkshop.Game.Items; using DaggerfallWorkshop.Game.Banking; using DaggerfallWorkshop.Game.Guilds; -using DaggerfallWorkshop.Game.Utility; using DaggerfallWorkshop.Game.MagicAndEffects.MagicEffects; using System.Collections.Generic; using DaggerfallWorkshop.Utility.AssetInjection; +using DaggerfallWorkshop.Game.Utility; using DaggerfallWorkshop.Game.Formulas; using DaggerfallWorkshop.Game.Utility.ModSupport; using DaggerfallWorkshop.Localization; @@ -209,7 +209,7 @@ void Start() playerGPS = GetComponent(); playerEnterExit = GetComponent(); mainCamera = GameManager.Instance.MainCamera; - playerLayerMask = ~(1 << LayerMask.NameToLayer("Player") | 1 << LayerMask.NameToLayer("Automap")); + playerLayerMask = ~(1 << LayerMask.NameToLayer("Player")); } void Update() diff --git a/Assets/Scripts/Game/PlayerEnterExit.cs b/Assets/Scripts/Game/PlayerEnterExit.cs index 6d17560415..045e462f1d 100644 --- a/Assets/Scripts/Game/PlayerEnterExit.cs +++ b/Assets/Scripts/Game/PlayerEnterExit.cs @@ -17,7 +17,6 @@ using DaggerfallConnect; using DaggerfallConnect.Arena2; using DaggerfallConnect.Utility; -using DaggerfallWorkshop.Game.Utility; using DaggerfallWorkshop.Game.Serialization; using DaggerfallWorkshop.Game.UserInterfaceWindows; using DaggerfallWorkshop.Game.Entity; @@ -1243,7 +1242,7 @@ private void SetStanding() // Snap player to ground RaycastHit hit; Ray ray = new Ray(transform.position, Vector3.down); - if (Physics.Raycast(ray, out hit, PlayerHeightChanger.controllerStandingHeight * 2f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(ray, out hit, PlayerHeightChanger.controllerStandingHeight * 2f)) { // Clear falling damage so player doesn't take damage if they transitioned into a dungeon while jumping GameManager.Instance.AcrobatMotor.ClearFallingDamage(); diff --git a/Assets/Scripts/Game/PlayerMotor.cs b/Assets/Scripts/Game/PlayerMotor.cs index 35ecb284f7..72e086f3c9 100644 --- a/Assets/Scripts/Game/PlayerMotor.cs +++ b/Assets/Scripts/Game/PlayerMotor.cs @@ -190,7 +190,7 @@ public bool StartRestGroundedCheck() // Collision fix for when player is levitating but feet are "close enough" to ground to rest // This is required as controller physics requires movement to process grounded collision normally Ray ray = new Ray(transform.position, Vector3.down); - return (Physics.Raycast(ray, controller.height / 2 + 0.2f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)); + return (Physics.Raycast(ray, controller.height / 2 + 0.2f)); } /// @@ -427,7 +427,7 @@ public Vector3 FindGroundPosition(float distance = 10) { RaycastHit hit; Ray ray = new Ray(transform.position, Vector3.down); - if (Physics.Raycast(ray, out hit, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(ray, out hit, distance)) return hit.point; return transform.position; @@ -438,7 +438,7 @@ public bool FixStanding(float extraHeight = 0, float extraDistance = 0) { RaycastHit hit; Ray ray = new Ray(transform.position + (Vector3.up * extraHeight), Vector3.down); - if (Physics.Raycast(ray, out hit, (controller.height * 2) + extraHeight + extraDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(ray, out hit, (controller.height * 2) + extraHeight + extraDistance)) { // Position player at hit position plus just over half controller height up transform.position = hit.point + Vector3.up * (controller.height * 0.65f); @@ -508,7 +508,7 @@ bool GetOnExteriorGroundMethod() // Must be outside and actually be standing on a terrain object not some other object (e.g. player ship) RaycastHit hit; - if (GameManager.Instance.PlayerEnterExit.IsPlayerInside || !Physics.Raycast(transform.position, Vector3.down, out hit, rayDistance * 2, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (GameManager.Instance.PlayerEnterExit.IsPlayerInside || !Physics.Raycast(transform.position, Vector3.down, out hit, rayDistance * 2)) { return false; } @@ -534,7 +534,7 @@ bool GetOnExteriorStaticGeometryMethod() // Must be outside and actually be standing on a terrain object not some other object (e.g. player ship) RaycastHit hit; - if (GameManager.Instance.PlayerEnterExit.IsPlayerInside || !Physics.Raycast(transform.position, Vector3.down, out hit, rayDistance * 2, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (GameManager.Instance.PlayerEnterExit.IsPlayerInside || !Physics.Raycast(transform.position, Vector3.down, out hit, rayDistance * 2)) { return false; } diff --git a/Assets/Scripts/Game/Questing/Actions/CreateFoe.cs b/Assets/Scripts/Game/Questing/Actions/CreateFoe.cs index 944d0f2650..1f4c591cf7 100644 --- a/Assets/Scripts/Game/Questing/Actions/CreateFoe.cs +++ b/Assets/Scripts/Game/Questing/Actions/CreateFoe.cs @@ -288,7 +288,7 @@ void PlaceFoeFreely(GameObject[] gameObjects, Transform parent, float minDistanc // Check for a hit Vector3 currentPoint; RaycastHit initialHit; - if (Physics.Raycast(ray, out initialHit, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(ray, out initialHit, maxDistance)) { float cos_normal = Vector3.Dot(- spawnDirection, initialHit.normal.normalized); if (cos_normal < 1e-6) @@ -313,12 +313,12 @@ void PlaceFoeFreely(GameObject[] gameObjects, Transform parent, float minDistanc // Must be able to find a surface below RaycastHit floorHit; ray = new Ray(currentPoint, Vector3.down); - if (!Physics.Raycast(ray, out floorHit, maxFloorDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!Physics.Raycast(ray, out floorHit, maxFloorDistance)) return; // Ensure this is open space Vector3 testPoint = floorHit.point + Vector3.up * separationDistance; - Collider[] colliders = Physics.OverlapSphere(testPoint, overlapSphereRadius, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + Collider[] colliders = Physics.OverlapSphere(testPoint, overlapSphereRadius); if (colliders.Length > 0) return; @@ -431,4 +431,4 @@ public override void RestoreSaveData(object dataIn) #endregion } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Game/Utility/FoeSpawner.cs b/Assets/Scripts/Game/Utility/FoeSpawner.cs index f4cb8cda10..b865b8006f 100644 --- a/Assets/Scripts/Game/Utility/FoeSpawner.cs +++ b/Assets/Scripts/Game/Utility/FoeSpawner.cs @@ -163,7 +163,7 @@ void PlaceFoeFreely(GameObject[] gameObjects, float minDistance = 5f, float maxD // Check for a hit Vector3 currentPoint; RaycastHit initialHit; - if (Physics.Raycast(ray, out initialHit, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(ray, out initialHit, maxDistance)) { float cos_normal = Vector3.Dot(-spawnDirection, initialHit.normal.normalized); if (cos_normal < 1e-6) @@ -188,12 +188,12 @@ void PlaceFoeFreely(GameObject[] gameObjects, float minDistance = 5f, float maxD // Must be able to find a surface below RaycastHit floorHit; ray = new Ray(currentPoint, Vector3.down); - if (!Physics.Raycast(ray, out floorHit, maxFloorDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!Physics.Raycast(ray, out floorHit, maxFloorDistance)) return; // Ensure this is open space Vector3 testPoint = floorHit.point + Vector3.up * separationDistance; - Collider[] colliders = Physics.OverlapSphere(testPoint, overlapSphereRadius, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + Collider[] colliders = Physics.OverlapSphere(testPoint, overlapSphereRadius); if (colliders.Length > 0) return; @@ -241,4 +241,4 @@ void DestroyOldFoeGameObjects(GameObject[] gameObjects) #endregion } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Game/Utility/PhysicsLayers.cs b/Assets/Scripts/Game/Utility/PhysicsLayers.cs deleted file mode 100644 index 424393b3e1..0000000000 --- a/Assets/Scripts/Game/Utility/PhysicsLayers.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Project: Daggerfall Unity -// Copyright: Copyright (C) 2009-2023 Daggerfall Workshop -// Web Site: http://www.dfworkshop.net -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/Interkarma/daggerfall-unity -// Original Author: Gavin Clayton (interkarma@dfworkshop.net) -// Contributors: -// -// Notes: -// - -using UnityEngine; - -namespace DaggerfallWorkshop.Game.Utility -{ - /// - /// Shared physics layer masks. - /// - public static class PhysicsLayers - { - public static int DefaultRaycastLayersWithoutAutomap - { - get { return Physics.DefaultRaycastLayers & ~(1 << LayerMask.NameToLayer("Automap")); } - } - } -} diff --git a/Assets/Scripts/Game/Utility/PhysicsLayers.cs.meta b/Assets/Scripts/Game/Utility/PhysicsLayers.cs.meta deleted file mode 100644 index e7f7a6fbd3..0000000000 --- a/Assets/Scripts/Game/Utility/PhysicsLayers.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d413ee3330123e8498e671b7d20b13e2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Terrain/StreamingWorld.cs b/Assets/Scripts/Terrain/StreamingWorld.cs index 5fac671981..37f14a7fc5 100644 --- a/Assets/Scripts/Terrain/StreamingWorld.cs +++ b/Assets/Scripts/Terrain/StreamingWorld.cs @@ -1598,7 +1598,7 @@ private bool FixStanding(Transform playerTransform, float playerHeight, float ex { RaycastHit hit; Ray ray = new Ray(playerTransform.position + (Vector3.up * extraHeight), Vector3.down); - if (Physics.Raycast(ray, out hit, (playerHeight * 2) + extraHeight + extraDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(ray, out hit, (playerHeight * 2) + extraHeight + extraDistance)) { // Position player at hit position plus just over half controller height up playerTransform.position = hit.point + Vector3.up * (playerHeight * 0.6f); @@ -1858,4 +1858,4 @@ protected virtual void RaiseOnFloatingOriginChangeEvent() #endregion } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Utility/AssetInjection/Components/FaceWall.cs b/Assets/Scripts/Utility/AssetInjection/Components/FaceWall.cs index b47f6df9ec..0563c59769 100644 --- a/Assets/Scripts/Utility/AssetInjection/Components/FaceWall.cs +++ b/Assets/Scripts/Utility/AssetInjection/Components/FaceWall.cs @@ -12,7 +12,6 @@ using System; using UnityEngine; using UnityEngine.Serialization; -using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Utility.AssetInjection { @@ -101,7 +100,7 @@ private void Start() private bool HitWall(Vector3 direction) { Vector3 worldSpaceDirection = transform.TransformDirection(direction); - return Physics.Raycast(gameObject.transform.position, worldSpaceDirection, MaxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + return Physics.Raycast(gameObject.transform.position, worldSpaceDirection, MaxDistance); } /// @@ -110,7 +109,7 @@ private bool HitWall(Vector3 direction) private void Move() { RaycastHit hitInfo; - if (Physics.Raycast(new Ray(transform.position, transform.forward), out hitInfo, MaxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (Physics.Raycast(new Ray(transform.position, transform.forward), out hitInfo, MaxDistance)) { Bounds bounds = meshRenderer.bounds; @@ -134,14 +133,14 @@ private void Align() Vector3 bottomPoint = gameObject.transform.position; bottomPoint.y = bounds.min.y; RaycastHit hitInfoBottom; - if (!Physics.Raycast(new Ray(bottomPoint, transform.forward), out hitInfoBottom, MaxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!Physics.Raycast(new Ray(bottomPoint, transform.forward), out hitInfoBottom, MaxDistance)) return; // Top point on bounds Vector3 topPoint = gameObject.transform.position; topPoint.y = bounds.max.y; RaycastHit hitInfoTop; - if (!Physics.Raycast(new Ray(topPoint, transform.forward), out hitInfoTop, MaxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!Physics.Raycast(new Ray(topPoint, transform.forward), out hitInfoTop, MaxDistance)) return; // Calculate angle and rotate @@ -152,4 +151,4 @@ private void Align() #endregion } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Utility/AssetInjection/Components/NPCModelRotator.cs b/Assets/Scripts/Utility/AssetInjection/Components/NPCModelRotator.cs index 36a6a21890..abb171f220 100644 --- a/Assets/Scripts/Utility/AssetInjection/Components/NPCModelRotator.cs +++ b/Assets/Scripts/Utility/AssetInjection/Components/NPCModelRotator.cs @@ -10,7 +10,6 @@ // using DaggerfallWorkshop.Game; -using DaggerfallWorkshop.Game.Utility; using UnityEngine; namespace DaggerfallWorkshop.Utility.AssetInjection @@ -54,7 +53,7 @@ private void Start() { closestDoorDistance = Vector3.Distance(transform.position, closestStaticDoorPos); - bool visible = !Physics.Raycast(transform.position, closestStaticDoorPos - transform.position, closestDoorDistance - 0.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + bool visible = !Physics.Raycast(transform.position, closestStaticDoorPos - transform.position, closestDoorDistance - 0.5f); if (visible) closestDoorVisible = true; } @@ -67,7 +66,7 @@ private void Start() //Debug.LogFormat("Door at {0}, centre {1} rot {2}", actionDoors[i].transform.position, doorCentre, actionDoors[i].transform.rotation); float distance = Vector3.Distance(transform.position, doorCentre); - bool visible = !Physics.Raycast(transform.position, doorCentre - transform.position, distance - 0.5f, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + bool visible = !Physics.Raycast(transform.position, doorCentre - transform.position, distance - 0.5f); if (visible) { diff --git a/Assets/Scripts/Utility/AssetInjection/Components/ObjectPositioner.cs b/Assets/Scripts/Utility/AssetInjection/Components/ObjectPositioner.cs index c01010e779..279e66251b 100644 --- a/Assets/Scripts/Utility/AssetInjection/Components/ObjectPositioner.cs +++ b/Assets/Scripts/Utility/AssetInjection/Components/ObjectPositioner.cs @@ -12,7 +12,6 @@ // #define TEST_TRANSLATION using UnityEngine; -using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Utility.AssetInjection { @@ -129,7 +128,7 @@ protected void Move(Vector3 direction) Ray ray = new Ray(bounds.center, transform.TransformDirection(direction)); RaycastHit hitInfo; - if (!Physics.Raycast(ray, out hitInfo, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!Physics.Raycast(ray, out hitInfo, maxDistance)) return; // Get the bound extent on the direction of the ray axis @@ -165,4 +164,4 @@ private static Vector3 GetDirection(Direction direction) Vector3.zero; } } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Utility/AssetInjection/Components/WallPropPositioner.cs b/Assets/Scripts/Utility/AssetInjection/Components/WallPropPositioner.cs index f4aaf3138e..cb6f2cf388 100644 --- a/Assets/Scripts/Utility/AssetInjection/Components/WallPropPositioner.cs +++ b/Assets/Scripts/Utility/AssetInjection/Components/WallPropPositioner.cs @@ -10,7 +10,6 @@ // using UnityEngine; -using DaggerfallWorkshop.Game.Utility; namespace DaggerfallWorkshop.Utility.AssetInjection { @@ -79,14 +78,14 @@ protected void Align(Vector3 direction) Vector3 bottomPoint = gameObject.transform.position; bottomPoint.y = bounds.min.y; RaycastHit hitInfoBottom; - if (!Physics.Raycast(new Ray(bottomPoint, worldSpaceDirection), out hitInfoBottom, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!Physics.Raycast(new Ray(bottomPoint, worldSpaceDirection), out hitInfoBottom, maxDistance)) return; // Top point on bounds Vector3 topPoint = gameObject.transform.position; topPoint.y = bounds.max.y; RaycastHit hitInfoTop; - if (!Physics.Raycast(new Ray(topPoint, worldSpaceDirection), out hitInfoTop, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!Physics.Raycast(new Ray(topPoint, worldSpaceDirection), out hitInfoTop, maxDistance)) return; // Calculate delta @@ -108,7 +107,7 @@ protected void Align(Vector3 direction) private bool HitWall(Vector3 direction) { Vector3 worldSpaceDirection = transform.TransformDirection(direction); - return Physics.Raycast(gameObject.transform.position, worldSpaceDirection, maxDistance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap); + return Physics.Raycast(gameObject.transform.position, worldSpaceDirection, maxDistance); } } } diff --git a/Assets/Scripts/Utility/GameObjectHelper.cs b/Assets/Scripts/Utility/GameObjectHelper.cs index 48e54fe07f..34cd5345ca 100644 --- a/Assets/Scripts/Utility/GameObjectHelper.cs +++ b/Assets/Scripts/Utility/GameObjectHelper.cs @@ -338,7 +338,7 @@ public static void AlignBillboardToGround(GameObject go, Vector2 size, float dis // Cast ray down to find ground below RaycastHit hit; Ray ray = new Ray(go.transform.position + new Vector3(0, 0.2f, 0), Vector3.down); - if (!Physics.Raycast(ray, out hit, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!Physics.Raycast(ray, out hit, distance)) return; // Position bottom just above ground by adjusting parent gameobject @@ -354,7 +354,7 @@ public static void AlignControllerToGround(CharacterController controller, float // Cast ray down from slightly above midpoint to find ground below RaycastHit hit; Ray ray = new Ray(controller.transform.position + new Vector3(0, 0.2f, 0), Vector3.down); - if (!Physics.Raycast(ray, out hit, distance, PhysicsLayers.DefaultRaycastLayersWithoutAutomap)) + if (!Physics.Raycast(ray, out hit, distance)) return; // Position bottom just above ground by adjusting parent gameobject @@ -1522,4 +1522,4 @@ public static Quaternion QuaternionFromMatrix(Matrix4x4 m) return q; } } -} +} \ No newline at end of file From 48106f4b052045358f85d5e2ad8746780df87c13 Mon Sep 17 00:00:00 2001 From: Vivian V Wing Date: Thu, 11 Jun 2026 12:42:46 -0700 Subject: [PATCH 5/5] Moved automap 10,000 meters below the world, so it no longer overlaps geo This solves the issue where it occasionally consumes raycasts meant to hit e.g. levers. --- Assets/Scripts/Game/Automap.cs | 73 ++++++++++++------- .../DaggerfallAutomapWindow.cs | 33 +++++---- 2 files changed, 65 insertions(+), 41 deletions(-) diff --git a/Assets/Scripts/Game/Automap.cs b/Assets/Scripts/Game/Automap.cs index dbe45a1551..a1f53367f1 100644 --- a/Assets/Scripts/Game/Automap.cs +++ b/Assets/Scripts/Game/Automap.cs @@ -168,6 +168,7 @@ public override string ToString() const float raycastDistanceDown = 3.0f; // 3 meters should be enough (note: flying too high will result in geometry not being revealed by this raycast const float raycastDistanceViewDirection = 30.0f; // don't want to make it too easy to discover big halls - although it shouldn't be to small as well const float raycastDistanceEntranceMarkerReveal = 100.0f; + static readonly Vector3 automapOffset = new Vector3(0, -10000.0f, 0); // positional offset of the automap geometry, so that it does not overlap real geo const float scanRateGeometryDiscoveryInHertz = 5.0f; // n times per second the discovery of new geometry/meshes is checked @@ -389,6 +390,22 @@ public void SetState(Dictionary savedDictAutomapDun dictAutomapDungeonsDiscoveryState = savedDictAutomapDungeonsDiscoveryState; } + /// + /// Conversion of real game world position to automap position + /// + public Vector3 ToAutomapPosition(Vector3 realPosition) + { + return realPosition + automapOffset; + } + + /// + /// Conversion of automap position to real game world position + /// + public Vector3 FromAutomapPosition(Vector3 automapPosition) + { + return automapPosition - automapOffset; + } + /// /// sets the number of dungeons that are memorized /// @@ -406,10 +423,10 @@ public void UpdateAutomapStateOnWindowPush() // since new teleporters could have been discovered by pc since last time map was open this must be checked here CreateTeleporterMarkers(); - gameobjectPlayerMarkerArrow.transform.position = gameObjectPlayerAdvanced.transform.position; + gameobjectPlayerMarkerArrow.transform.position = ToAutomapPosition(gameObjectPlayerAdvanced.transform.position); gameobjectPlayerMarkerArrow.transform.rotation = gameObjectPlayerAdvanced.transform.rotation; - gameobjectBeaconPlayerPosition.transform.position = gameObjectPlayerAdvanced.transform.position + rayPlayerPosOffset; + gameobjectBeaconPlayerPosition.transform.position = ToAutomapPosition(gameObjectPlayerAdvanced.transform.position + rayPlayerPosOffset); // create camera (if not present) that will render automap level geometry CreateAutomapCamera(); @@ -653,7 +670,7 @@ public bool UpdateMouseHoverOverGameObjects(Vector2 screenPosition) } } - gameobjectTeleporterConnection.transform.position = (connection.teleporterEntrance.position + connection.teleporterExit.position) * 0.5f; + gameobjectTeleporterConnection.transform.position = ToAutomapPosition((connection.teleporterEntrance.position + connection.teleporterExit.position) * 0.5f); gameobjectTeleporterConnection.transform.localScale = new Vector3(0.2f, (connection.teleporterEntrance.position - connection.teleporterExit.position).magnitude * 0.5f, 0.2f); gameobjectTeleporterConnection.transform.rotation = Quaternion.FromToRotation(Vector3.up, (connection.teleporterEntrance.position - connection.teleporterExit.position)); @@ -763,7 +780,7 @@ public void TryToAddOrEditUserNoteMarkerOnDungeonSegmentAtScreenPosition(Vector2 if (!nearestHit.Value.transform.name.StartsWith(NameGameobjectUserNoteMarkerSubStringStart)) { // add a new user note marker - Vector3 spawningPosition = (nearestHit.Value.point) + nearestHit.Value.normal * 0.7f; + Vector3 spawningPosition = FromAutomapPosition(nearestHit.Value.point + nearestHit.Value.normal * 0.7f); // test if there is already a user note marker near to the requested spawning position var enumerator = listUserNoteMarkers.GetEnumerator(); @@ -825,7 +842,7 @@ public void TryCenterAutomapCameraOnDungeonSegmentAtScreenPosition(Vector2 scree if (nearestHit.HasValue) { - float distance = (cameraAutomap.transform.position - gameObjectPlayerAdvanced.transform.position).magnitude; + float distance = (cameraAutomap.transform.position - ToAutomapPosition(gameObjectPlayerAdvanced.transform.position)).magnitude; cameraAutomap.transform.position = (nearestHit.Value.point); cameraAutomap.transform.position -= cameraAutomap.transform.forward * distance; } @@ -858,9 +875,10 @@ public void TryTeleportPlayerToDungeonSegmentAtScreenPosition(Vector2 screenPosi if (nearestHit.HasValue) { - gameObjectPlayerAdvanced.transform.position = nearestHit.Value.point + Vector3.up * 0.1f; - gameobjectBeaconPlayerPosition.transform.position = nearestHit.Value.point + rayPlayerPosOffset; - gameobjectPlayerMarkerArrow.transform.position = nearestHit.Value.point + rayPlayerPosOffset; + Vector3 realHitPoint = FromAutomapPosition(nearestHit.Value.point); + gameObjectPlayerAdvanced.transform.position = realHitPoint + Vector3.up * 0.1f; + gameobjectBeaconPlayerPosition.transform.position = ToAutomapPosition(realHitPoint + rayPlayerPosOffset); + gameobjectPlayerMarkerArrow.transform.position = ToAutomapPosition(realHitPoint + rayPlayerPosOffset); } // don't forget to update micro map texture, so new player position is visualized correctly on micro map @@ -1080,11 +1098,12 @@ void Update() #endif // main raycast (on Colliders in layer "Automap") - bool didHit1 = Physics.Raycast(rayStartPos, rayDirection, out hit1, rayDistance, 1 << layerAutomap); + Vector3 automapRayStartPos = ToAutomapPosition(rayStartPos); + bool didHit1 = Physics.Raycast(automapRayStartPos, rayDirection, out hit1, rayDistance, 1 << layerAutomap); // 2nd (protection) raycast (on Colliders in layer "Automap") with offset (protection against hole in daggerfall geometry prevention) - bool didHit2 = Physics.Raycast(rayStartPos + offsetSecondProtectionRaycast, rayDirection, out hit2, rayDistance, 1 << layerAutomap); + bool didHit2 = Physics.Raycast(automapRayStartPos + offsetSecondProtectionRaycast, rayDirection, out hit2, rayDistance, 1 << layerAutomap); // 3rd (protection) raycast (on Colliders in layer "Automap") with offset (protection against hole in daggerfall geometry prevention) - bool didHit3 = Physics.Raycast(rayStartPos + offsetThirdProtectionRaycast, rayDirection, out hit3, rayDistance, 1 << layerAutomap); + bool didHit3 = Physics.Raycast(automapRayStartPos + offsetThirdProtectionRaycast, rayDirection, out hit3, rayDistance, 1 << layerAutomap); #if DEBUG_RAYCASTS //Debug.Log(String.Format("hitTG1: {0}, hitTG2: {1}, hitTG3: {2}, hit1: {3}, hit2: {4}, hit3: {5}", didHitTrueLevelGeometry1, didHitTrueLevelGeometry2, didHitTrueLevelGeometry3, didHit1, didHit2, didHit3)); @@ -1197,7 +1216,7 @@ void CheckForNewlyDiscoveredMeshes() int layerMask = (1 << layerPlayer) + 1; // test against player and level geometry (+1... == 1 << 1 == "Default" layer == level geometry) - Vector3 entranceMarkerPos = gameObjectEntrancePositionCubeMarker.transform.position; + Vector3 entranceMarkerPos = FromAutomapPosition(gameObjectEntrancePositionCubeMarker.transform.position); Vector3 playerColliderPos = playerCollider.transform.position; //GameManager.Instance.PlayerGPS.transform.position; //Camera.main.transform.position; // raycast 1 Vector3 rayStartPos = entranceMarkerPos; @@ -1283,7 +1302,7 @@ private void UpdateSlicingPositionY() { float slicingPositionY; if (!DaggerfallUnity.Settings.AutomapAlwaysMaxOutSliceLevel) - slicingPositionY = gameObjectPlayerAdvanced.transform.position.y + Camera.main.transform.localPosition.y + slicingBiasY; + slicingPositionY = ToAutomapPosition(gameObjectPlayerAdvanced.transform.position + Camera.main.transform.localPosition).y + slicingBiasY; else slicingPositionY = float.MaxValue; Shader.SetGlobalFloat("_SclicingPositionY", slicingPositionY); @@ -1324,7 +1343,7 @@ private void SetupBeacons(StaticDoor ?entranceDoor = null) gameobjectPlayerMarkerArrow.layer = layerAutomap; gameobjectPlayerMarkerArrow.AddComponent(); } - gameobjectPlayerMarkerArrow.transform.position = gameObjectPlayerAdvanced.transform.position; + gameobjectPlayerMarkerArrow.transform.position = ToAutomapPosition(gameObjectPlayerAdvanced.transform.position); gameobjectPlayerMarkerArrow.transform.rotation = gameObjectPlayerAdvanced.transform.rotation; if (!gameobjectBeaconPlayerPosition) @@ -1340,7 +1359,7 @@ private void SetupBeacons(StaticDoor ?entranceDoor = null) //SetMaterialTransparency(material); gameobjectBeaconPlayerPosition.GetComponent().material = material; } - gameobjectBeaconPlayerPosition.transform.position = gameObjectPlayerAdvanced.transform.position + rayPlayerPosOffset; + gameobjectBeaconPlayerPosition.transform.position = ToAutomapPosition(gameObjectPlayerAdvanced.transform.position + rayPlayerPosOffset); if (!gameobjectBeaconRotationPivotAxis) { @@ -1411,17 +1430,19 @@ private void SetupBeacons(StaticDoor ?entranceDoor = null) { // entrance marker to dungeon start marker DaggerfallDungeon dungeon = GameManager.Instance.DungeonParent.GetComponentInChildren(); - gameobjectBeaconEntrancePosition.transform.position = dungeon.StartMarker.transform.position + rayEntrancePosOffset; + gameobjectBeaconEntrancePosition.transform.position = ToAutomapPosition(dungeon.StartMarker.transform.position + rayEntrancePosOffset); gameobjectBeaconEntrancePosition.SetActive(false); // set do undiscovered } else { // entrance marker to current position (position player entered) StaticDoor door = entranceDoor.Value; - gameobjectBeaconEntrancePosition.transform.position = door.ownerRotation * door.buildingMatrix.MultiplyPoint3x4(door.centre); - gameobjectBeaconEntrancePosition.transform.position += door.ownerPosition; + Vector3 entrancePosition = door.ownerRotation * door.buildingMatrix.MultiplyPoint3x4(door.centre); + entrancePosition += door.ownerPosition; + gameobjectBeaconEntrancePosition.transform.position = ToAutomapPosition(entrancePosition); gameobjectBeaconEntrancePosition.SetActive(true); // set do discovered } + } private void DestroyBeacons() @@ -1543,7 +1564,7 @@ private GameObject CreateUserMarker(int id, Vector3 spawningPosition) } GameObject gameObjectUserNoteMarker = CreateDiamondShapePrimitive(); gameObjectUserNoteMarker.transform.SetParent(gameObjectUserNoteMarkers.transform); - gameObjectUserNoteMarker.transform.position = spawningPosition; + gameObjectUserNoteMarker.transform.position = ToAutomapPosition(spawningPosition); gameObjectUserNoteMarker.name = NameGameobjectUserNoteMarkerSubStringStart + id; Material materialUserNoteMarker = new Material(Shader.Find("Standard")); materialUserNoteMarker.color = new Color(1.0f, 0.55f, 0.0f); @@ -1594,7 +1615,7 @@ private void AddTeleporterMarkerOnMap(TeleporterTransform startPoint, Teleporter { GameObject gameObjectTeleporterEntrance = new GameObject(teleporterEntranceName); gameObjectTeleporterEntrance.transform.SetParent(gameobjectTeleporterMarkers.transform); - gameObjectTeleporterEntrance.transform.position = startPoint.position; // + Vector3.up * 1.0f; + gameObjectTeleporterEntrance.transform.position = ToAutomapPosition(startPoint.position); // + Vector3.up * 1.0f; gameObjectTeleporterEntrance.transform.rotation = startPoint.rotation; gameObjectTeleporterEntrance.transform.Rotate(0.0f, 90.0f, 0.0f); gameObjectTeleporterEntrance.layer = layerAutomap; @@ -1618,7 +1639,7 @@ private void AddTeleporterMarkerOnMap(TeleporterTransform startPoint, Teleporter { GameObject gameObjectTeleporterExit = new GameObject(teleporterExitName); gameObjectTeleporterExit.transform.SetParent(gameobjectTeleporterMarkers.transform); - gameObjectTeleporterExit.transform.position = endPoint.position; // + Vector3.up * 0.2f; + gameObjectTeleporterExit.transform.position = ToAutomapPosition(endPoint.position); // + Vector3.up * 0.2f; //gameObjectTeleporterExit.transform.rotation = endPoint.rotation; //gameObjectTeleporterExit.transform.Rotate(0.0f, 180.0f, 0.0f); gameObjectTeleporterExit.transform.rotation = startPoint.rotation; // take rotation from portal entrance @@ -1812,7 +1833,7 @@ private void GetRayCastNearestHitOnAutomapLayer(Vector2 screenPosition, out Rayc float nearestDistance = float.MaxValue; foreach (RaycastHit hit in hits) { - if ((hit.distance < nearestDistance) && (hit.collider.gameObject.GetComponent().enabled)) + if ((hit.distance < nearestDistance) && hit.collider.gameObject.TryGetComponent(out MeshRenderer meshRend) && meshRend.enabled) { nearestHit = hit; nearestDistance = hit.distance; @@ -1856,7 +1877,7 @@ private void CreateIndoorGeometryForAutomap(StaticDoor door) gameobjectInterior.transform.SetParent(gameobjectGeometry.transform); // copy position and rotation from real level geometry - gameobjectGeometry.transform.position = elem.transform.position; + gameobjectGeometry.transform.position = ToAutomapPosition(elem.transform.position); gameobjectGeometry.transform.rotation = elem.transform.rotation; // do this (here in createIndoorGeometryForAutomap()) analog in the same way and the same place like in createDungeonGeometryForAutomap() @@ -1920,7 +1941,7 @@ private void CreateDungeonGeometryForAutomap() gameobjectDungeon.transform.SetParent(gameobjectGeometry.transform); // copy position and rotation from real level geometry - gameobjectGeometry.transform.position = elem.transform.position; + gameobjectGeometry.transform.position = ToAutomapPosition(elem.transform.position); gameobjectGeometry.transform.rotation = elem.transform.rotation; // do this here when DaggerfallDungeon GameObject is present, so that a call to SetupBeacons() will not fail (it needs the DaggerfallDungeon component of this GameObject) @@ -1950,7 +1971,7 @@ private void AddWater(GameObject parent, short nativeBlockWaterLevel) if (nativeBlockWaterLevel == 10000) return; - float waterLevel = nativeBlockWaterLevel * -1 * MeshReader.GlobalScale; + float waterLevel = ToAutomapPosition(new Vector3(0, nativeBlockWaterLevel * -1 * MeshReader.GlobalScale, 0)).y; MeshRenderer[] renderers = parent.GetComponentsInChildren(); if (renderers != null) @@ -2556,7 +2577,7 @@ private void RaiseOnInjectMeshAndMaterialPropertiesEvent(bool resetDiscoveryStat if (GameManager.Instance.IsPlayerInsideBuilding) playerIsInsideBuilding = true; - Vector3 playerAdvancedPos = gameObjectPlayerAdvanced.transform.position; + Vector3 playerAdvancedPos = ToAutomapPosition(gameObjectPlayerAdvanced.transform.position); Material automapMaterial = new Material(Shader.Find("Daggerfall/Automap")); automapMaterial.SetColor("_WaterColor", GameManager.Instance.PlayerEnterExit.UnderwaterFog.waterMapColor); diff --git a/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallAutomapWindow.cs b/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallAutomapWindow.cs index 96ce3fb761..bd19a74279 100644 --- a/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallAutomapWindow.cs +++ b/Assets/Scripts/Game/UserInterfaceWindows/DaggerfallAutomapWindow.cs @@ -880,10 +880,10 @@ public override void Update() { case AutomapViewMode.View2D: default: - dragSpeedCompensated = dragSpeedInTopView * Vector3.Magnitude(Camera.main.transform.position - cameraAutomap.transform.position); + dragSpeedCompensated = dragSpeedInTopView * Vector3.Magnitude(automap.ToAutomapPosition(Camera.main.transform.position) - cameraAutomap.transform.position); break; case AutomapViewMode.View3D: - dragSpeedCompensated = dragSpeedInView3D * Vector3.Magnitude(Camera.main.transform.position - cameraAutomap.transform.position); + dragSpeedCompensated = dragSpeedInView3D * Vector3.Magnitude(automap.ToAutomapPosition(Camera.main.transform.position) - cameraAutomap.transform.position); break; } @@ -1159,8 +1159,9 @@ private void ResetCameraPosition() /// private void ResetCameraTransformViewFromTop() { - cameraAutomap.transform.position = Camera.main.transform.position + Vector3.up * cameraHeightViewFromTop; - cameraAutomap.transform.LookAt(Camera.main.transform.position); + Vector3 automapPlayerPosition = automap.ToAutomapPosition(Camera.main.transform.position); + cameraAutomap.transform.position = automapPlayerPosition + Vector3.up * cameraHeightViewFromTop; + cameraAutomap.transform.LookAt(automapPlayerPosition); SaveCameraTransformViewFromTop(); } @@ -1170,8 +1171,9 @@ private void ResetCameraTransformViewFromTop() private void ResetCameraTransformView3D() { Vector3 viewDirectionInXZ = Vector3.forward; - cameraAutomap.transform.position = Camera.main.transform.position - viewDirectionInXZ * cameraBackwardDistance + Vector3.up * cameraHeightView3D; - cameraAutomap.transform.LookAt(Camera.main.transform.position); + Vector3 automapPlayerPosition = automap.ToAutomapPosition(Camera.main.transform.position); + cameraAutomap.transform.position = automapPlayerPosition - viewDirectionInXZ * cameraBackwardDistance + Vector3.up * cameraHeightView3D; + cameraAutomap.transform.LookAt(automapPlayerPosition); SaveCameraTransformView3D(); } @@ -1216,7 +1218,7 @@ private void RestoreOldCameraTransformView3D() /// private void ResetRotationPivotAxisPositionViewFromTop() { - rotationPivotAxisPositionViewFromTop = gameObjectPlayerAdvanced.transform.position; + rotationPivotAxisPositionViewFromTop = automap.ToAutomapPosition(gameObjectPlayerAdvanced.transform.position); automap.RotationPivotAxisPosition = rotationPivotAxisPositionViewFromTop; } @@ -1225,7 +1227,7 @@ private void ResetRotationPivotAxisPositionViewFromTop() /// private void ResetRotationPivotAxisPositionView3D() { - rotationPivotAxisPositionView3D = gameObjectPlayerAdvanced.transform.position; + rotationPivotAxisPositionView3D = automap.ToAutomapPosition(gameObjectPlayerAdvanced.transform.position); automap.RotationPivotAxisPosition = rotationPivotAxisPositionView3D; } @@ -1275,7 +1277,7 @@ private Vector3 GetRotationPivotAxisPosition() rotationPivotAxisPosition = rotationPivotAxisPositionView3D; break; default: - rotationPivotAxisPosition = gameObjectPlayerAdvanced.transform.position; + rotationPivotAxisPosition = automap.ToAutomapPosition(gameObjectPlayerAdvanced.transform.position); break; } return (rotationPivotAxisPosition); @@ -1615,7 +1617,7 @@ private void ActionMoveSliceLevel(float bias) /// private void ActionZoomIn(float zoomSpeed) { - float zoomSpeedCompensated = zoomSpeed * Vector3.Magnitude(Camera.main.transform.position - cameraAutomap.transform.position); + float zoomSpeedCompensated = zoomSpeed * Vector3.Magnitude(automap.ToAutomapPosition(Camera.main.transform.position) - cameraAutomap.transform.position); Vector3 translation = cameraAutomap.transform.forward * zoomSpeedCompensated; cameraAutomap.transform.position += translation; UpdateAutomapView(); @@ -1626,7 +1628,7 @@ private void ActionZoomIn(float zoomSpeed) /// private void ActionZoomOut(float zoomSpeed) { - float zoomSpeedCompensated = zoomSpeed * Vector3.Magnitude(Camera.main.transform.position - cameraAutomap.transform.position); + float zoomSpeedCompensated = zoomSpeed * Vector3.Magnitude(automap.ToAutomapPosition(Camera.main.transform.position) - cameraAutomap.transform.position); Vector3 translation = -cameraAutomap.transform.forward * zoomSpeedCompensated; cameraAutomap.transform.position += translation; UpdateAutomapView(); @@ -1829,19 +1831,20 @@ private void ActionSwitchFocusToNextBeaconObject() /// the GameObject to focus at private void SwitchFocusToGameObject(GameObject gameobjectInFocus) { + Vector3 focusPosition = (gameobjectInFocus == gameObjectPlayerAdvanced) ? automap.ToAutomapPosition(gameobjectInFocus.transform.position) : gameobjectInFocus.transform.position; Vector3 newPosition; switch (automapViewMode) { case AutomapViewMode.View2D: newPosition = cameraAutomap.transform.position; - newPosition.x = gameobjectInFocus.transform.position.x; - newPosition.z = gameobjectInFocus.transform.position.z; + newPosition.x = focusPosition.x; + newPosition.z = focusPosition.z; cameraAutomap.transform.position = newPosition; UpdateAutomapView(); break; case AutomapViewMode.View3D: - float computedCameraBackwardDistance = Vector3.Magnitude(cameraAutomap.transform.position - gameobjectInFocus.transform.position); - newPosition = gameobjectInFocus.transform.position - cameraAutomap.transform.forward * computedCameraBackwardDistance; + float computedCameraBackwardDistance = Vector3.Magnitude(cameraAutomap.transform.position - focusPosition); + newPosition = focusPosition - cameraAutomap.transform.forward * computedCameraBackwardDistance; cameraAutomap.transform.position = newPosition; UpdateAutomapView(); break;