playMaker

Author Topic: Help with setting destination in Navmesh.  (Read 6995 times)

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Help with setting destination in Navmesh.
« on: October 27, 2013, 02:35:05 PM »
Hi,
I have a enemy using Navmesh to get to a collection of pickups.  The pickups need to be dynamic as in, they can be picked up by the player as well, so I've set a boolean on each object to say if its available or not.
I'm checking this condition every frame, so when the enemy enters the trigger zone of where the pickups are, it knows which it can pick up.
When the enemy reaches the trigger, I have a Find Closest action to see which item is closest to the enemy, so then I want to update the destination of the Navmesh to that item and then loop the FSM's so the enemy can go from one item to the next.
Problem is, I cant set the destination in the Navmesh to the closest pickup item.  The only options are Vector3, item, etc.  So if I set it to Vector3, I dont know how to convert the results from Find Closest, to a Vector 3.

Yanifska

  • Full Member
  • ***
  • Posts: 163
    • My Portfolio
Re: Help with setting destination in Navmesh.
« Reply #1 on: October 27, 2013, 02:50:44 PM »
Hi,

Find closest will return a GameObject you can then use GetPosition to get the location in a Vector3 and use it as a Destination.
Or you can use SetAgentDestinationAsAGameObject  ;)
Visit my portfolio: http://www.yanivcahoua.com/

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: Help with setting destination in Navmesh.
« Reply #2 on: October 27, 2013, 02:58:36 PM »
Hi,

Find closest will return a GameObject you can then use GetPosition to get the location in a Vector3 and use it as a Destination.
Or you can use SetAgentDestinationAsAGameObject  ;)

Thanks for you help. I'm out at the moment, but I'll give it a go when I get back.
Is SetAgentDestinationAsAGameObject a property in the navmesh?
Also is there a better way to do what I'm trying to do, or does it sound ok?

Yanifska

  • Full Member
  • ***
  • Posts: 163
    • My Portfolio
Re: Help with setting destination in Navmesh.
« Reply #3 on: October 27, 2013, 03:54:06 PM »
I am no expert, but I have been playing quite intensively with these actions last few weeks. And I am doing something similar to you most of the time. (If  I understood you well).
You should check the sample scenes, it helped me a bit with set destination.

SetAgentDestinationAsAGameObject is an action just like SetDestination. The difference is that it will follow a moving object. Also check the GetRemainingDistance to get an event when the Agent reach its destination. I had trouble understanding this but the sample scenes helped me.

I have a lot more to learn, but I am working quite intensively and learning fast, so don't hesitate to ask or check my threads in the forum, I am asking a lot of questions concerning pathfinding.
Hopefully we can help each other.
Visit my portfolio: http://www.yanivcahoua.com/

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: Help with setting destination in Navmesh.
« Reply #4 on: October 27, 2013, 04:02:20 PM »
Hi,

Find closest will return a GameObject you can then use GetPosition to get the location in a Vector3 and use it as a Destination.
Or you can use SetAgentDestinationAsAGameObject  ;)

Tried it and unfortunately it doesn't work :(
I can't work out how to get a Vector 3 of whichever pickup item is closest. I've tried Store Object and Store Distance in the Find Closest.  If I use Store Object, I use a GameObject variable, but it asks for a GameObject.  I cant add one of the pickup items in here, because I need it to be dynamic.  So I need a variable that is a result of the Find Closest and then set that as the Destination in the Navmesh. 

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: Help with setting destination in Navmesh.
« Reply #5 on: October 27, 2013, 04:13:57 PM »
I am no expert, but I have been playing quite intensively with these actions last few weeks. And I am doing something similar to you most of the time. (If  I understood you well).
You should check the sample scenes, it helped me a bit with set destination.

SetAgentDestinationAsAGameObject is an action just like SetDestination. The difference is that it will follow a moving object. Also check the GetRemainingDistance to get an event when the Agent reach its destination. I had trouble understanding this but the sample scenes helped me.

I have a lot more to learn, but I am working quite intensively and learning fast, so don't hesitate to ask or check my threads in the forum, I am asking a lot of questions concerning pathfinding.
Hopefully we can help each other.

Hi, thanks again.  Which example scenes are you refering to? Do they have the SetAgentDestinationAsAGameObject actions?
I'd be happy to help you, but I think you are further along than me ;)
 

Yanifska

  • Full Member
  • ***
  • Posts: 163
    • My Portfolio
Re: Help with setting destination in Navmesh.
« Reply #6 on: October 27, 2013, 04:34:13 PM »
In the Find Closest you have to store a Gameobject variable call it Pickup.
Then you put a Get Position action and  you use the Pickup variable as the gameobject and you store its position in a Vector3 Variable. Then you can use SetDestination to the the vector3

Another way is FindClosest with Pickup variable ( GameObject) and then SetDestination As GameObject with the Pickup variable as a Gameobject.

If it's not working maybe the problem lies beforehand
Visit my portfolio: http://www.yanivcahoua.com/

Yanifska

  • Full Member
  • ***
  • Posts: 163
    • My Portfolio
Re: Help with setting destination in Navmesh.
« Reply #7 on: October 27, 2013, 04:38:23 PM »
Visit my portfolio: http://www.yanivcahoua.com/

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: Help with setting destination in Navmesh.
« Reply #8 on: October 28, 2013, 11:21:28 AM »
In the Find Closest you have to store a Gameobject variable call it Pickup.
Then you put a Get Position action and  you use the Pickup variable as the gameobject and you store its position in a Vector3 Variable. Then you can use SetDestination to the the vector3

Another way is FindClosest with Pickup variable ( GameObject) and then SetDestination As GameObject with the Pickup variable as a Gameobject.

If it's not working maybe the problem lies beforehand

Thanks, I have it working now.  What I didn't understand, was when you set a GameObject variable, it asks for a GameObject to be assigned.  But just leaving that empty, so the Pickup variable gets assigned, has got it working. 
So now I have to go about checking for the next closest pickup item at regular intervals. I think checking every frame is probably overkill.  Is there a way to use the Find Closest every other frame, or every 0.5 a second?

Yanifska

  • Full Member
  • ***
  • Posts: 163
    • My Portfolio
Re: Help with setting destination in Navmesh.
« Reply #9 on: October 29, 2013, 07:50:45 AM »
you can use a loop, with GetNextChild if your object are parented, or maybe have an array and loop through it ( i don't remember the name of the action, but it has the word Next in it, install ArrayMaker first to get the actions related to array management).
Then you can add a wait action to set a time pause between each iteration.
good luck,
Yaniv
Visit my portfolio: http://www.yanivcahoua.com/