Hello,
I add a navMesh to my sphere in order to move it, without it being able to cross the end of the zone.
I add this script to my sphere :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class ClickAndMove : MonoBehaviour
{
private NavMeshAgent _agent;
void Start()
{
_agent = GetComponent<NavMeshAgent>();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hitInfo;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo,100))
{
_agent.SetDestination(hitInfo.point);
}
}
}
}
Problem:
If I click, the sphere moves towards the clicked place, but the camera is badly positioned. The camera rotates when it should stay behind the sphere. Do you know what this problem is related to?
thanks in advance