playMaker

Author Topic: A* pathfinding (stable 0v841)  (Read 231090 times)

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (stable 0v841)
« Reply #240 on: September 29, 2013, 04:30:44 AM »
I'm sorry for not replying to you guys earlier, I just went apartment hunting in Munich and my camping site surprisingly didn't have any internet.

@Muppetpuppet
I think there's little I can do without a test scene. I have no idea why your actors are behaving the way they are. If it is too difficult to create a test scene from your project, you could also send me an NDA and then I could have a look directly at your project.

@Yanifska
You're the second person who says that unity crashes on smooth turn. I will need to investigate this asap.
For now the failed event is only called if you did something wrong in the action setup (eg if you follow a path that does not exist). I reimplemented the failed event as an event that is sent when the final node position is further than the failed distance away from your target position, but apparently I forgot to add this to the latest release. In such an event it would not even start to move the actor, though having an option to move the actor to the closest valid node and to then send the failed event sounds quite useful.
As for follow vs followTo : Follow will stop moving once it's within finish distance of the target, but it will continue following the target once that target has moved away again. FollowTo will send a finished event once it's within finish distance of the target.

Perfect finish will add the target position as a last waypoint to the path. This means no matter where the real calculated path ends, it will always beeline from the last node on the path directly to the target. It is useful if your target is an empty that might be "between" some nodes.
The reason why your actor is jittering without the Perfect Finish mode is because you are most likely using an Absolute Finish Distance Mode . This means, it will only finish the movement action if the distance between the center of your actor and the center of your target is less than the FinishDistance. This is never true, because the distance between the last node on your path and the target is bigger than your FinishDistance. This is why absolute should probably only be used with high FinishDistance settings, eg when you have an archer that has a long range attack, and you're making him attack something, then you first need to move to the target position, but if he's maybe on a mountain ridge he would not have to move all the way down to shoot his arrow if the target is somewhere below him. In this case an absolute finish distance check is what you need.


Ok, so let me list all the problems for the recent version up, so I can work on fixing them:
-
- Smooth Turns somehow crashes
- FailedEvent still not dependent on FailedDistance
- LateFailedDistanceCheck option (to first move to the closest node, then do the failed distance check)
- Fast actors on dense graphs cause errors (This is something that I personally need to fix, though it might take a lot of effort)
- Shadow problems (beelines)

I also think it might be for the best to implement a "simple" and "advanced" mode, where the simple mode could hide and auto-set some options to make it easier to create a working/non-stuttering action for people who just started using this.


Bugfixes I've made so far (just a list for me :D) :
- Time.frameCount <= 1 in the path creation and the OnUpdate function to produce valid paths even if the user spawns the actor before the graphs are initialized.
- added debug log message to check your real start and end path position (regarding the beeline issue, it seems that's because the target position is equal to the actor position at the time when the action first starts)
« Last Edit: October 03, 2013, 10:42:25 AM by kiriri »
Best,
Sven

muppetpuppet

  • Junior Playmaker
  • **
  • Posts: 77
Re: A* pathfinding (stable 0v841)
« Reply #241 on: September 30, 2013, 03:50:46 AM »
No worries,  I'll just share my project on drop-box,, Just as its my first playmaker project, it might be a bit noobish ;).

Ill PM you

Yanifska

  • Full Member
  • ***
  • Posts: 163
    • My Portfolio
Re: A* pathfinding (stable 0v841)
« Reply #242 on: September 30, 2013, 02:55:16 PM »
Sven,

thank you so much for this great post !!
I need to take time to dig more in the options and I hope you can make a update soon.
I am not sure that a "noob mode" is really necessary, but it may help.
What we really need is a well written documentation...for the least
It seems that this is the only pathfinding package available for Playmaker on Unity Indie so I believe this is a really important work you have begun.

Yaniv
Visit my portfolio: http://www.yanivcahoua.com/

Yanifska

  • Full Member
  • ***
  • Posts: 163
    • My Portfolio
Re: A* pathfinding (stable 0v841)
« Reply #243 on: October 04, 2013, 06:41:50 AM »
Hi Sven,

I found something else that bothers me :
it seems the MoveTo action never finishes at all even when it does reach the destination.
Is it a bug or do I need to change my setup ?
-Yaniv
Visit my portfolio: http://www.yanivcahoua.com/

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (stable 0v841)
« Reply #244 on: October 04, 2013, 06:55:43 AM »
the never stopping thing can have a number of reasons. And this is one of the things that really needs documentation :D So let's start a FAQ and save it in the second post of this thread.


1# My MoveTo action never finishes, even when the actor already reached the end of the path. What can I do?
Good question! There may be a number of reasons for this. The least obvious is the usage of the "absolute" FinishDistanceMode, combined with a low FinishDistance. In this case your actor walks towards the last node on the path, but even then the absolute distance between him and the target can still be higher than the FinishDistance (eg if you have a Gridgraph and your target is right in the centre of one of those "gridsquares".) In this case you can either :

1) Up your FinishDistance
2) Enable the ExactFinish option which adds your target's center as a last node to the path
3) Change the FinishDistanceMode to something like Last or AbsoluteLast, which  checks the distance between the actor and the last node on the path instead of the distance between the actor and the target.

You should always note that sometimes your target might be underground. In this case you should make sure to check the IgnoreY option, which will also ignore any y coordinates in the FinishDistance modes.



Hope this helps :)
Best,
Sven

LoneCipher

  • Playmaker Newbie
  • *
  • Posts: 29
Re: A* pathfinding (stable 0v841)
« Reply #245 on: October 07, 2013, 03:42:55 PM »
Loving this pathfinding solution. This works amazingly well.

I have a performance question for a click to walk setup:
I have a pointgraph set up around doors and openings
clicking the ground creates 2 nodes. one at the player's position, and one at the destination
The graph is scanned.
If the 2 new nodes are linked up, you will walk in a straight line to the destination.
If the 2 nodes cannot link up, they are already added to the pointgraph (during the scan) and the best route is taken

because of all the graph scanning each click, you can tank your fps if you spam-click.

Is there a way to see if there is a direct connection between the 2 nodes without scanning?

LoneCipher

  • Playmaker Newbie
  • *
  • Posts: 29
Re: A* pathfinding (stable 0v841)
« Reply #246 on: October 07, 2013, 03:57:06 PM »
Also, is there a way to create a path from a spesific graph?

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (stable 0v841)
« Reply #247 on: October 07, 2013, 04:30:46 PM »
To see if there is a direct path between 2 nodes you would require something along the lines of a "planecast" (2D raycast) , which Unity unfortunately does not provide. You could emulate such a behaviour with a box collider rigidbody though. I think there is a function called rigidbody sweep that should make it possible to get whether the rigidbody collides with something (without having to wait for the next frame).

As for restricting path calculation to one graph only, it is possible via node tags, but I have yet to implement this into the action.
If you wan to do it, then make sure you set the Path.walkabilityMask of the path right after the path is created and before it is being calculated. I don't know when I'll be able to implement it myself, it may take me as long as the weekend to finally find some time to spend on this project again, sorry.

Anyways, I'm really glad about your positive feedback :)
Best,
Sven

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (stable 0v841)
« Reply #248 on: October 09, 2013, 04:06:56 AM »
Since I know that this will be a big issue once Unity 4.3 is released, let me clarify some things. Right now, neither my plugin nor Aron Granberg's is ready for the 2D mode. Unity always had this oddity in that the y axis defined height (all other game engines use the z axis for height) . So it was a real surprise for me that they now chose to use the x and y axis for their 2D mode. This means ignore y won't work and I'll likely have to add another ignore z mode. I think they did it this way to allow people to reuse physics plugins , but still it's annoying :D. On top of that a GridGraph behaves weirdly when rotated.

So what you could do to make this work already is use pointGraphs and use a calculate path coupled with a translate path and a move to. On the pointGraph you would have to calculate the walkability of each node yourself, which you can easily do with a raycast on each node.

And yes, I know this is horrible :D Perhaps I'll find some time on the weekend to ask Aron on his plans and to write that ignoreZ option.
Best,
Sven

LoneCipher

  • Playmaker Newbie
  • *
  • Posts: 29
Re: A* pathfinding (stable 0v841)
« Reply #249 on: October 11, 2013, 05:31:50 PM »
Is there a way to have an ai use a specific graph?
Lets say i want one to use a point graph and the other to use a grid graph.
i see that there is an action for "get graph in graphs" but i have no idea how to use it. :(

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (stable 0v841)
« Reply #250 on: October 17, 2013, 06:14:18 AM »
Not that I know of. I might be wrong though. However, you can specify certain Tags for the path. So you can just tag your one graph as "big" and the other as "small". At least in theory you can. In practice, I still didn't get around to write a custom editor to handle tag masks, so it's not yet possible to do with my actions. It's a tad tricky so I won't promise anything, but I might find the time for it this weekend.

I just started university now so the pace of updates will unfortunately decrease a lot from now on. Sorry if this causes any inconveniences.
Best,
Sven

mweyna

  • Full Member
  • ***
  • Posts: 242
Re: A* pathfinding (stable 0v841)
« Reply #251 on: October 17, 2013, 11:08:01 AM »
What is the easiest way to have my object face forward while navigating a path? I've tried using all the look at variations however they all basically fail to rotate the object to face it's current target on the node.

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (stable 0v841)
« Reply #252 on: October 17, 2013, 11:23:30 AM »
Is smooth look at direction not working for you? You can use the direction value the moveTo action returns.
Best,
Sven

LoneCipher

  • Playmaker Newbie
  • *
  • Posts: 29
Re: A* pathfinding (stable 0v841)
« Reply #253 on: October 17, 2013, 12:16:56 PM »
Quote
I just started university now so the pace of updates will unfortunately decrease a lot from now on. Sorry if this causes any inconveniences.

This is all charity work so you don't need to apologize.
Thank you for all the hard work you have done so far :)

mweyna

  • Full Member
  • ***
  • Posts: 242
Re: A* pathfinding (stable 0v841)
« Reply #254 on: October 17, 2013, 12:27:47 PM »
Smooth Look At Direction doesn't seem to be working for me, unless I've set this up wrong. Here is my setup -



What basically happens currently is the unit (those little guys on the far left of the screen stay in that orientation you currently see, regardless of where they are moving to. The path is being created successfully, however the guys just aren't using their X forward to face it.