Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Getting a player-controlled object to move to another object that is not strictly tied to a navmesh

Discussion in 'Navigation' started by dann96, Dec 26, 2014.

  1. dann96

    dann96

    Joined:
    Dec 6, 2014
    Posts:
    113
    Basically, what I want to do is whenever a player clicks on a specifically tagged object in a map, the player model uses the navmesh to navigate to that object (like a point-and-click game).

    I feel like there is a really easy answer to this that I'm missing, but either way, could someone explain to me how to achieve this exactly? Also, C# would be nice if you provide code.
     
  2. CodeElemental

    CodeElemental

    Joined:
    Feb 6, 2014
    Posts:
    15
    First you need to check which obect is clicked.
    - Either check every mouse click and do a raycast in direction to the mouse cursor to get the clicked object.
    - Possibly you can do this with checking onmouseenter/leave inside the object but I'm not exactly sure it would work.

    After you are certain that the object is clicked, get it's position on the navmesh and use SetDestination or CalculatePath to make the agnet go there.