From ce6628f247dfbf44defab5622ea1833677fe747c Mon Sep 17 00:00:00 2001 From: JaXt0r <120568393+JaXt0r@users.noreply.github.com> Date: Fri, 24 May 2024 05:07:57 +0200 Subject: [PATCH 1/3] fix(NpcHelper): Lowered lookup distance. (Otherwise PEE fps will be seeked within nearly whole OC.) --- Assets/GothicVR/Scripts/Manager/NpcHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/GothicVR/Scripts/Manager/NpcHelper.cs b/Assets/GothicVR/Scripts/Manager/NpcHelper.cs index 0e8c1ce7..9898e8e4 100644 --- a/Assets/GothicVR/Scripts/Manager/NpcHelper.cs +++ b/Assets/GothicVR/Scripts/Manager/NpcHelper.cs @@ -19,7 +19,7 @@ namespace GVR.Manager { public static class NpcHelper { - private const float fpLookupDistance = 20f; // meter + private const float fpLookupDistance = 7f; // meter static NpcHelper() { From b125de6cdeb7236be1fdd9eeadf7fdaee5eb76ec Mon Sep 17 00:00:00 2001 From: JaXt0r <120568393+JaXt0r@users.noreply.github.com> Date: Fri, 31 May 2024 04:57:33 +0200 Subject: [PATCH 2/3] fix(DestinationReached): Whenever NPCs walk to an FP or WP, they will now hit it as we leverage Vector3.Distance() (which is better, as some NPCs spawn next/in colliders already). --- .../Resources/Prefabs/Vobs/zCVobSpot.prefab | 22 ----------- .../Resources/Prefabs/WayPoint.prefab | 22 ----------- .../Scripts/Debugging/GvrGizmosDebug.cs | 19 +++++++++ .../Scripts/Debugging/GvrGizmosDebug.cs.meta | 3 ++ Assets/GothicVR/Scripts/Globals/Constants.cs | 3 ++ .../AbstractAnimationAction.cs | 12 +----- .../AbstractRotateAnimationAction.cs | 6 +-- .../AbstractWalkAnimationAction.cs | 27 +++++++++---- .../Npc/Actions/AnimationActions/GoToFp.cs | 16 +------- .../Npc/Actions/AnimationActions/GoToNpc.cs | 8 ++++ .../Npc/Actions/AnimationActions/GoToWp.cs | 31 ++++++--------- .../Npc/Actions/AnimationActions/UseMob.cs | 8 +--- Assets/GothicVR/Scripts/Npc/AiHandler.cs | 2 +- .../Scripts/Npc/RootCollisionHandler.cs | 39 ------------------- 14 files changed, 73 insertions(+), 145 deletions(-) create mode 100644 Assets/GothicVR/Scripts/Debugging/GvrGizmosDebug.cs create mode 100644 Assets/GothicVR/Scripts/Debugging/GvrGizmosDebug.cs.meta diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/zCVobSpot.prefab b/Assets/GothicVR/Resources/Prefabs/Vobs/zCVobSpot.prefab index 1c04d66d..0ef987ad 100644 --- a/Assets/GothicVR/Resources/Prefabs/Vobs/zCVobSpot.prefab +++ b/Assets/GothicVR/Resources/Prefabs/Vobs/zCVobSpot.prefab @@ -12,7 +12,6 @@ GameObject: - component: {fileID: 5681108792341746749} - component: {fileID: 4250102412515220408} - component: {fileID: 3429925256554951498} - - component: {fileID: 5979848652310601961} m_Layer: 2 m_Name: zCVobSpot m_TagString: PxVob_zCVobSpot @@ -98,24 +97,3 @@ MeshRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_AdditionalVertexStreams: {fileID: 0} ---- !u!135 &5979848652310601961 -SphereCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 3434156045681339339} - m_Material: {fileID: 0} - m_IncludeLayers: - serializedVersion: 2 - m_Bits: 0 - m_ExcludeLayers: - serializedVersion: 2 - m_Bits: 0 - m_LayerOverridePriority: 0 - m_IsTrigger: 1 - m_ProvidesContacts: 0 - m_Enabled: 1 - serializedVersion: 3 - m_Radius: 0.5 - m_Center: {x: 0, y: -0.0000019073486, z: -0.000015258789} diff --git a/Assets/GothicVR/Resources/Prefabs/WayPoint.prefab b/Assets/GothicVR/Resources/Prefabs/WayPoint.prefab index f82867b0..d38ca960 100644 --- a/Assets/GothicVR/Resources/Prefabs/WayPoint.prefab +++ b/Assets/GothicVR/Resources/Prefabs/WayPoint.prefab @@ -11,7 +11,6 @@ GameObject: - component: {fileID: 2665078943939252271} - component: {fileID: 1188047755481711733} - component: {fileID: 6851058351796696224} - - component: {fileID: 3747938385529500483} m_Layer: 2 m_Name: WayPoint m_TagString: Untagged @@ -84,24 +83,3 @@ MeshRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_AdditionalVertexStreams: {fileID: 0} ---- !u!65 &3747938385529500483 -BoxCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4344130464614125633} - m_Material: {fileID: 0} - m_IncludeLayers: - serializedVersion: 2 - m_Bits: 0 - m_ExcludeLayers: - serializedVersion: 2 - m_Bits: 0 - m_LayerOverridePriority: 0 - m_IsTrigger: 1 - m_ProvidesContacts: 0 - m_Enabled: 1 - serializedVersion: 3 - m_Size: {x: 1, y: 1, z: 1} - m_Center: {x: 0, y: 0, z: 0} diff --git a/Assets/GothicVR/Scripts/Debugging/GvrGizmosDebug.cs b/Assets/GothicVR/Scripts/Debugging/GvrGizmosDebug.cs new file mode 100644 index 00000000..787f5ca2 --- /dev/null +++ b/Assets/GothicVR/Scripts/Debugging/GvrGizmosDebug.cs @@ -0,0 +1,19 @@ +using UnityEngine; + +namespace GVR.Debugging +{ + /// + /// Add it to an object where you want to draw some information. + /// + public class GvrGizmosDebug : MonoBehaviour + { + private void OnDrawGizmos() + { + var pos = transform.position; + var up = new Vector3(pos.x, 100, pos.z); + var down = new Vector3(pos.x, -100, pos.z); + + Gizmos.DrawLine(up, down); + } + } +} diff --git a/Assets/GothicVR/Scripts/Debugging/GvrGizmosDebug.cs.meta b/Assets/GothicVR/Scripts/Debugging/GvrGizmosDebug.cs.meta new file mode 100644 index 00000000..1b77b25e --- /dev/null +++ b/Assets/GothicVR/Scripts/Debugging/GvrGizmosDebug.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 178aac5ad24c4eae81d675be3b0136e2 +timeCreated: 1717123074 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Globals/Constants.cs b/Assets/GothicVR/Scripts/Globals/Constants.cs index 20241a8a..eb399ea2 100644 --- a/Assets/GothicVR/Scripts/Globals/Constants.cs +++ b/Assets/GothicVR/Scripts/Globals/Constants.cs @@ -55,6 +55,9 @@ public static class Constants // We need to set the scale so that collision and NPC animation is starting at the right spot. public static Vector3 VobZSScale = new(0.1f, 0.1f, 0.1f); + // e.g. for NPCs to check if they reached a FreePoint already. Value is based on best guess/testing. + public const float CloseToThreshold = 0.6f; + static Constants() { LoadingMaterial = new Material(ShaderWorldLit); diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractAnimationAction.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractAnimationAction.cs index 2599afcc..8733aa64 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractAnimationAction.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractAnimationAction.cs @@ -132,22 +132,12 @@ public virtual void AnimationEndEventCallback(SerializableEventEndSignal eventDa IsFinishedFlag = true; } - - public virtual void OnCollisionEnter(Collision coll) - { } - public virtual void OnTriggerEnter(Collider coll) - { } - - public virtual void OnCollisionExit(Collision coll) - { } - public virtual void OnTriggerExit(Collider coll) - { } /// /// Called every update cycle. /// Can be used to handle frequent things internally. /// - public virtual void Tick(Transform transform) + public virtual void Tick() { } /// diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractRotateAnimationAction.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractRotateAnimationAction.cs index dba4defc..73ce9933 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractRotateAnimationAction.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractRotateAnimationAction.cs @@ -51,11 +51,11 @@ private string GetRotateModeAnimationString() } } - public override void Tick(Transform transform) + public override void Tick() { - base.Tick(transform); + base.Tick(); - HandleRotation(transform); + HandleRotation(NpcGo.transform); } /// diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractWalkAnimationAction.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractWalkAnimationAction.cs index 1cf7479e..a860016b 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractWalkAnimationAction.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractWalkAnimationAction.cs @@ -1,6 +1,7 @@ using System; using GVR.Creator; using GVR.Data.ZkEvents; +using GVR.Globals; using GVR.Manager; using GVR.Vm; using UnityEngine; @@ -28,6 +29,8 @@ protected AbstractWalkAnimationAction(AnimationAction action, GameObject npcGo) /// protected abstract Vector3 GetWalkDestination(); + protected abstract void OnDestinationReached(); + public override void Start() { base.Start(); @@ -35,9 +38,9 @@ public override void Start() PhysicsHelper.EnablePhysicsForNpc(Props); } - public override void Tick(Transform transform) + public override void Tick() { - base.Tick(transform); + base.Tick(); if (IsFinishedFlag) return; @@ -46,16 +49,16 @@ public override void Tick(Transform transform) { case WalkState.Initial: walkState = WalkState.Rotate; - HandleRotation(transform, GetWalkDestination(), false); + HandleRotation(NpcGo.transform, GetWalkDestination(), false); return; case WalkState.Rotate: - HandleRotation(transform, GetWalkDestination(), false); + HandleRotation(NpcGo.transform, GetWalkDestination(), false); return; case WalkState.Walk: - HandleWalk(transform); + HandleWalk(Props.colliderRootMotion.transform); return; case WalkState.WalkAndRotate: - HandleRotation(transform, GetWalkDestination(), true); + HandleRotation(NpcGo.transform, GetWalkDestination(), true); return; case WalkState.Done: return; // NOP @@ -87,11 +90,21 @@ private void StartWalk() walkState = WalkState.Walk; } + private void HandleWalk(Transform transform) { - // NOP + var npcPos = transform.position; + var walkPos = GetWalkDestination(); + var npcDistPos = new Vector3(npcPos.x, walkPos.y, npcPos.z); + + var distance = Vector3.Distance(npcDistPos, walkPos); + + // FIXME - Scorpio is above FP, but values don't represent it. + if (distance < Constants.CloseToThreshold) + OnDestinationReached(); } + private void HandleRotation(Transform transform, Vector3 destination, bool includesWalking) { var pos = transform.position; diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs index dab19edc..dc8770c4 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs @@ -1,5 +1,4 @@ using GVR.Data.ZkEvents; -using GVR.GothicVR.Scripts.Manager; using GVR.Manager; using GVR.Vob.WayNet; using UnityEngine; @@ -26,18 +25,7 @@ public override void Start() // Fix - If NPC is spawned directly in front of the FP, we start transition immediately (otherwise trigger/collider won't be called). if (Vector3.Distance(npcPos, fp!.Position) < 1f) - FreePointReached(); - } - - public override void OnTriggerEnter(Collider coll) - { - if (walkState != WalkState.Walk) - return; - - if (coll.gameObject.name != fp.Name) - return; - - FreePointReached(); + OnDestinationReached(); } public override void AnimationEndEventCallback(SerializableEventEndSignal eventData) @@ -52,7 +40,7 @@ protected override Vector3 GetWalkDestination() return fp.Position; } - private void FreePointReached() + protected override void OnDestinationReached() { Props.CurrentFreePoint = fp; fp.IsLocked = true; diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNpc.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNpc.cs index 4f5db6b8..2c0317ab 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNpc.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNpc.cs @@ -33,5 +33,13 @@ public override void AnimationEndEventCallback(SerializableEventEndSignal eventD IsFinishedFlag = false; } + + protected override void OnDestinationReached() + { + AnimationEndEventCallback(new SerializableEventEndSignal(nextAnimation: "")); + + walkState = WalkState.Done; + IsFinishedFlag = true; + } } } diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToWp.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToWp.cs index 293bdac3..a8b31ff1 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToWp.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToWp.cs @@ -38,21 +38,26 @@ public override void Start() destinationWaypoint.Name)); } - public override void OnTriggerEnter(Collider coll) + protected override Vector3 GetWalkDestination() { - if (walkState != WalkState.Walk) - return; + return route.Peek().Position; + } - if (coll.gameObject.name != route.First().Name) - return; + public override void AnimationEndEventCallback(SerializableEventEndSignal eventData) + { + base.AnimationEndEventCallback(eventData); - // FIXME - get current waypoint object - // props.currentWayPoint = coll.gameObject. + IsFinishedFlag = false; + } + protected override void OnDestinationReached() + { route.Pop(); if (route.Count == 0) { + AnimationEndEventCallback(new SerializableEventEndSignal(nextAnimation: "")); + walkState = WalkState.Done; IsFinishedFlag = true; } @@ -62,17 +67,5 @@ public override void OnTriggerEnter(Collider coll) walkState = WalkState.WalkAndRotate; } } - - protected override Vector3 GetWalkDestination() - { - return route.Peek().Position; - } - - public override void AnimationEndEventCallback(SerializableEventEndSignal eventData) - { - base.AnimationEndEventCallback(eventData); - - IsFinishedFlag = false; - } } } diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/UseMob.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/UseMob.cs index 0cb9c20f..eca3c584 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/UseMob.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/UseMob.cs @@ -83,14 +83,8 @@ private GameObject GetNearestMobSlot(GameObject mob) return slot; } - public override void OnTriggerEnter(Collider coll) + protected override void OnDestinationReached() { - if (walkState != WalkState.Walk) - return; - - if (coll.gameObject != slotGo) - return; - StartMobUseAnimation(); } diff --git a/Assets/GothicVR/Scripts/Npc/AiHandler.cs b/Assets/GothicVR/Scripts/Npc/AiHandler.cs index e2a9f591..52e19f29 100644 --- a/Assets/GothicVR/Scripts/Npc/AiHandler.cs +++ b/Assets/GothicVR/Scripts/Npc/AiHandler.cs @@ -30,7 +30,7 @@ private void Start() /// private void Update() { - properties.currentAction.Tick(transform); + properties.currentAction.Tick(); // Add new milliseconds when stateTime shall be measured. if (properties.isStateTimeActive) diff --git a/Assets/GothicVR/Scripts/Npc/RootCollisionHandler.cs b/Assets/GothicVR/Scripts/Npc/RootCollisionHandler.cs index beebd4d9..4dbe1094 100644 --- a/Assets/GothicVR/Scripts/Npc/RootCollisionHandler.cs +++ b/Assets/GothicVR/Scripts/Npc/RootCollisionHandler.cs @@ -1,48 +1,9 @@ -using GVR.Extensions; -using GVR.Properties; using UnityEngine; namespace GVR.Npc { public class RootCollisionHandler : BasePlayerBehaviour { - private void OnCollisionEnter(Collision coll) - { - properties.currentAction?.OnCollisionEnter(coll); - } - - private void OnTriggerEnter(Collider coll) - { - properties.currentAction?.OnTriggerEnter(coll); - } - - private void OnCollisionExit(Collision coll) - { - properties.currentAction?.OnCollisionExit(coll); - - // FIXME - As we handle FreePoint locking via Colliders, we can't just say "free" whenever collider is left as a rotation can create this state already. - // FIXME - Instead we need to handle unlocking via game logic. E.g. whenever a new state starts, clear our NPCs lock setting. - // // If NPC walks out of a FreePoint, it gets freed. - // if (coll.gameObject.name.StartsWithIgnoreCase("FP_") && - // coll.gameObject.TryGetComponent(out var vobSpotProperties)) - // vobSpotProperties.fp.IsLocked = false; - } - - /// - /// Sometimes a currentAnimation needs this information. Sometimes it's just for a FreePoint to clear up. - /// - private void OnTriggerExit(Collider coll) - { - properties.currentAction?.OnTriggerExit(coll); - - // FIXME - As we handle FreePoint locking via Colliders, we can't just say "free" whenever collider is left as a rotation can create this state already. - // FIXME - Instead we need to handle unlocking via game logic. E.g. whenever a new state starts, clear our NPCs lock setting. - // // If NPC walks out of a FreePoint, it gets freed. - // if (coll.gameObject.name.StartsWithIgnoreCase("FP_") && - // coll.gameObject.TryGetComponent(out var vobSpotProperties)) - // vobSpotProperties.fp.IsLocked = false; - } - private void Update() { // As we use legacy animations, we can't use RootMotion. We therefore need to rebuild it. From 7b7beaf0dab1e4af4ea6cef0a26b6340e99b18ac Mon Sep 17 00:00:00 2001 From: JaXt0r <120568393+JaXt0r@users.noreply.github.com> Date: Fri, 31 May 2024 05:05:17 +0200 Subject: [PATCH 3/3] rem(GoToFp): Unused lines of code removed. --- .../GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs index dc8770c4..019ad356 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs @@ -22,10 +22,6 @@ public override void Start() var npcPos = NpcGo.transform.position; fp = WayNetHelper.FindNearestFreePoint(npcPos, destination); - - // Fix - If NPC is spawned directly in front of the FP, we start transition immediately (otherwise trigger/collider won't be called). - if (Vector3.Distance(npcPos, fp!.Position) < 1f) - OnDestinationReached(); } public override void AnimationEndEventCallback(SerializableEventEndSignal eventData)