fixing navmesh

This commit is contained in:
2024-05-27 22:32:55 +03:00
parent 4a59cee5e6
commit 4e467184cd
5 changed files with 16 additions and 40 deletions
-32
View File
@@ -936,7 +936,6 @@ GameObject:
- component: {fileID: 2624062824825965710}
- component: {fileID: 1031066880471145595}
- component: {fileID: 2225985379201912198}
- component: {fileID: 7790104718454169547}
m_Layer: 3
m_Name: Floor
m_TagString: Untagged
@@ -1033,37 +1032,6 @@ MeshCollider:
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &7790104718454169547
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5866443053939422291}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a5ac11cc976e418e8d13136b07e1f52, type: 3}
m_Name:
m_EditorClassIdentifier:
m_AgentTypeID: 0
m_CollectObjects: 0
m_Size: {x: 10, y: 10, z: 10}
m_Center: {x: 0, y: 2, z: 0}
m_LayerMask:
serializedVersion: 2
m_Bits: 8
m_UseGeometry: 0
m_DefaultArea: 0
m_GenerateLinks: 0
m_IgnoreNavMeshAgent: 1
m_IgnoreNavMeshObstacle: 1
m_OverrideTileSize: 0
m_TileSize: 256
m_OverrideVoxelSize: 0
m_VoxelSize: 0.1
m_MinRegionArea: 2
m_NavMeshData: {fileID: 23800000, guid: b850b50568fa8244c8b801f983427ee9, type: 2}
m_BuildHeightMesh: 0
--- !u!1 &6307399704129379229
GameObject:
m_ObjectHideFlags: 0
Binary file not shown.
+7 -1
View File
@@ -58,7 +58,13 @@ public class Player : BaseCharacter
public void SetPosition(Transform desiredPosition)
{
_navAgent.Warp(desiredPosition.position);
if (!_navAgent.isOnNavMesh)
{
transform.position = desiredPosition.position;
_navAgent.enabled = false;
_navAgent.enabled = true;
}
var t=_navAgent.Warp(desiredPosition.position);
_navAgent.updatePosition = false;
Rotate(desiredPosition.forward * -1);
}
@@ -4,15 +4,15 @@ using UnityEngine;
public class IndoorController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
void Awake()
{
var indoor = GameManager.Instance.BuildingSystem.Indoor;
Instantiate(indoor.Prefab, Vector3.zero, Quaternion.identity);
var transform =Instantiate(indoor.Prefab, Vector3.zero, Quaternion.identity);
Player.Instance.NavAgent.Warp(SpawnPlayer(indoor));
// If the NavMeshSurface is not assigned in the Inspector, try to find it
var navMeshSurface = indoor.Prefab.GetComponentInChildren<NavMeshSurface>();
Player.Instance.NavAgent.enabled = true;
var navMeshSurface = transform.GetComponentInChildren<NavMeshSurface>();
// Build the NavMesh
if (navMeshSurface != null)
{
@@ -23,6 +23,7 @@ public class IndoorController : MonoBehaviour
Debug.LogError("NavMeshSurface is not assigned and not found on the GameObject.");
}
SpawnPlayer(indoor);
}
private Vector3 SpawnPlayer(IndoorSO indoor)
@@ -37,6 +38,7 @@ public class IndoorController : MonoBehaviour
{
interactable = spawn.GetComponent<BaseInteractableObject>();
Player.Instance.SetPosition(interactable._interactionPoint);
break;
}
}
}
+1 -1
View File
@@ -75,7 +75,7 @@ NavMeshProjectSettings:
agentTypeID: 0
agentRadius: 0.3
agentHeight: 1.8
agentSlope: 45
agentSlope: 26
agentClimb: 0.3
ledgeDropHeight: 0
maxJumpAcrossDistance: 0