fixing navmesh
This commit is contained in:
@@ -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)
|
||||
{
|
||||
@@ -22,7 +22,8 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user