Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion S1API/Entities/Schedule/ActionSpecs/LocationDialogueSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using S1ObjectScripts = ScheduleOne.ObjectScripts;
#endif
using UnityEngine;
using UnityEngine.AI;
using S1API.Map;
using S1API.Vehicles;

Expand Down Expand Up @@ -112,11 +113,20 @@ void IScheduleActionSpec.ApplyTo(NPCSchedule schedule)
if (action == null)
return;

// Project destination to navmesh height so the game's 3D distance checks
// use a position consistent with where the NPC actually walks.
Vector3 markerPosition = Destination;
NavMeshHit navHit;
if (NavMesh.SamplePosition(Destination, out navHit, 5f, NavMesh.AllAreas))
{
markerPosition = new Vector3(Destination.x, navHit.position.y, Destination.z);
}

// Create destination marker in NPC's dedicated container
var destinationTransform = NPCDestinationContainer.CreateDestinationMarker(
schedule.NPC.gameObject.name,
"Marker",
Destination,
markerPosition,
Forward);

if (destinationTransform != null)
Expand Down
19 changes: 16 additions & 3 deletions S1API/Entities/Schedule/ActionSpecs/WalkToSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using S1ObjectScripts = ScheduleOne.ObjectScripts;
#endif
using UnityEngine;
using UnityEngine.AI;
using S1API.Map;
using S1API.Vehicles;

Expand Down Expand Up @@ -111,11 +112,23 @@ void IScheduleActionSpec.ApplyTo(NPCSchedule schedule)
}
}

// Project destination to navmesh height so the game's 3D distance checks
// (WalkResult.Success threshold and IsAtDestination) use a position consistent
// with where the NPC actually walks. Without this, a Y-coordinate mismatch > 1 unit
// causes WalkResult.Partial instead of Success, and ReachedDestination() never fires,
// so FaceDirection is never called.
Vector3 markerPosition = Destination;
NavMeshHit navHit;
if (NavMesh.SamplePosition(Destination, out navHit, 5f, NavMesh.AllAreas))
{
markerPosition = new Vector3(Destination.x, navHit.position.y, Destination.z);
}

// Create destination marker in NPC's dedicated container
var destinationTransform = NPCDestinationContainer.CreateDestinationMarker(
schedule.NPC.gameObject.name,
"Destination",
Destination,
schedule.NPC.gameObject.name,
"Destination",
markerPosition,
forwardDirection);

if (destinationTransform != null)
Expand Down
4 changes: 4 additions & 0 deletions S1API/S1API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Reference Include="$(Il2CppAssembliesPath)\UnityEngine.ImageConversionModule.dll" />
<Reference Include="$(Il2CppAssembliesPath)\UnityEngine.PhysicsModule.dll" />
<Reference Include="$(Il2CppAssembliesPath)\Unity.TextMeshPro.dll" />
<Reference Include="$(Il2CppAssembliesPath)\UnityEngine.AIModule.dll" />

<Reference Include="$(Il2CppAssembliesPath)\Il2CppFishNet.Runtime.dll" Condition="'$(Configuration)' == 'Il2CppMelon'" />
<Reference Include="$(Il2CppAssembliesPath)\FishNet.Runtime.dll" Condition="'$(Configuration)' == 'Il2CppBepInEx'" />
Expand Down Expand Up @@ -111,6 +112,9 @@
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>$(MonoAssembliesPath)/UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AIModule">
<HintPath>$(MonoAssembliesPath)/UnityEngine.AIModule.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>$(MonoAssembliesPath)/Unity.TextMeshPro.dll</HintPath>
</Reference>
Expand Down
Loading