Search Unity

Navigation description

Discussion in 'Navigation' started by elmar1028, Nov 27, 2014.

  1. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,359
    Seeing this thread leaves me consufed

    What is this thread about?
     
  2. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    NavMesh? :D
     
  3. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    My navmeshAgent doesn't move despite using agent.setDestination(). I placed it in Update().

    ??
     
  4. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,359
    Oooo. Now I get it! Never thought about that. Thanks :D
    Could be renamed to "NavMesh" :p
     
  5. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Did you set its speed to more than 0? Did you check if the path was unvalid?
     
  6. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    I got it working, I was using an y value that was not located on the mesh... at least I think that is the reason.


    However, I have a new issue. My agent does not move in two z directions. Only one. So I tap screen, convert to world space, move agent. He will move away from cam, but never towards.


    Code (csharp):
    1.  
    2.  
    3.     void setMoveToPos(Vector2 moveToPos){
    4.         Vector3 worldPos = Cam_Main.ScreenToWorldPoint(new Vector3(moveToPos.x, moveToPos.y, -18.6f));
    5.         targetPoint = new Vector3(-worldPos.x, worldPos.y, agent.transform.position.z);
    6.         moveActive = true;
    7.        
    8.     }
    9.  
     
  7. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Answer...
    Use raycast, hit.point.
     
  8. Hatttrick

    Hatttrick

    Joined:
    Aug 29, 2014
    Posts:
    2
    I imported a level as one hole mesh and added this script to it.


    Well I get to "Debug.Log("We click on nothing!");"

    I tried changing the front and rear clip planes of the camera. Static none static...

    First I thought it was me scaling the mesh that was the problem. Later I scaled it in 3dsmax and used Xform before exporting it to FBX format. I export the level as four meshes under the same parent.

    I use 3dsmax 2010, Unity 5 b14 on Windows 64 bit.

    To test I introduce a Unity plane and add the same script to it. Then the script works, like ray testing don't work on imported poly soup meshes..

    usingUnityEngine;
    usingSystem.Collections;

    publicclassClickSetPosition : MonoBehaviour {

    private GameObjectgo = null;
    private PropertiesAndCoroutinessn = null;

    voidAwake()
    {
    Debug.Log ("Awake started");
    go = GameObject.Find("MyCube");

    if (go == null)
    {
    Debug.Log ("find couldn't find MyCube");
    }
    else
    {
    Debug.Log ("MyCube was found using Find.");
    sn = go.GetComponent<PropertiesAndCoroutines> ();
    }
    //other = (PropertiesAndCoroutines) go.GetComponent(typeof(PropertiesAndCoroutines));
    Debug.Log ("onAwake ended");
    }
    void Update()
    {
    if (Input.GetMouseButtonDown(0))
    {
    System.Console.WriteLine("Entered game settings menu.");
    Debug.Log ("Mouse button down next make ray.");

    Rayray = Camera.main.ScreenPointToRay (Input.mousePosition);

    Debug.Log ("Now try physics and Raycast to get RaycastHit...");

    RaycastHithit;

    boolresult = Physics.Raycast(ray, outhit);

    Debug.DrawLine(Camera.main.transform.position, hit.point, Color.red);

    if (result == false)
    {
    Debug.Log("We click on nothing!");
    }
    else
    {
    Debug.Log ("OK physics worked and we clicked on something, see if we got the plane..");

    if (hit.collider.gameObject == gameObject)
    {
    Debug.Log ("hit!");

    if (sn == null)
    {
    Debug.Log ("Couldn't get script sn == null !!!");
    }
    else
    {
    Debug.Log ("Found script! Using it!");
    sn.Target = hit.point;
    Debug.Log ("Success!!");
    }
    }
    }
    }
    }
     
  9. Hatttrick

    Hatttrick

    Joined:
    Aug 29, 2014
    Posts:
    2
    OK add Mesh collider component to all level parts imported solved this.
     
  10. Babblu

    Babblu

    Joined:
    Mar 14, 2015
    Posts:
    1
    My scenes will tend to have few static obstacles (or none), and only a handful of dynamically placed obstacles on a flat plane. Is it worth using Navmesh or should I just create my own simple navigation code?






    ____________________
    FSL: