I had a scene set as the following picture.
And a NavMesh baked as the following picture.
But my “player” (The left-bottom corner sphere) don’t go where I want it want to go!
Source Codes:
public Camera cam;
public NavMeshAgent agent;
public GameObject particle;
// Update is called once per frame
private void Start()
{
particle.GetComponent<Renderer>().material.color = Color.red;
}
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray,out hit))
{
Vector3 v = hit.point;
agent.SetDestination(v);
Instantiate(particle,v,transform.rotation);
}
}
}
Could somebody please help me out!?
Much appreciated!!!
PS.
I found out through my “particle” that after first few hits, the “hit position” starts to “float”!
That’s why my “particle” became bigger!
It doesn’t “hit” the plane no more!
It always hit at somewhere above the plane!
That’s why my “player” can NOT go to the destination!
Could somebody teach me how to fix it please!
Much appreciated!