playMaker

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

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (beta)
« Reply #15 on: December 15, 2012, 07:17:48 AM »
Sorry for not getting beack to this sooner. I'm a freelancer so I never know when next I'll get work which generally needs to be done ASAP  :o .
Today I'll add some more actions. Like, I've already created an action which cheaply finds out whether a path is possible. It can be used every frame without any noticable frame drop. NExt up is an action which checks if an update graph action would make a path impossible (eg. TowerDefense, tower becomes red if you block the path.)
I'll update the packages at the top in a few hours :)

Hi, I couldn't wait and I decided to implement the FollowTarget action. It works decently with a catch... it's executed as long as you are in a following target state, meaning that you can't set it to follow a target and move on to another state. Anyway, for my project the job gets done, so I just left it like that.

Maybe someone here can improve it. By the way, I was concerned with too many path recalculations, but performance seems ok (100+ agents moving around at 60FPS). If someone knows more about all this, no need to ask for my permission. As this is basically a mashup of kiriri's script, I suppose he would be the one to ask
Nice, I didn't even try that to be honest. I feared that in larger scenes it may cause errors if you recalculate it again and again . However surprisingly enough, your action seems to run smoothly and it really doesn't hit the framerate all that much... Aaron really did some impressive work on his library :)
I'll see if I can find a  more subtle solution than the recalculation of the entire path either way. I think there was something like update path or the like in the documentation. May be more useful if you want a lot of npcs on a mobile device too.

Since I can only really create actions for 3.x (you think twice about updating if it costs the price of a small car :S) I'll let it be up to you to implement the necessary things for 4.x . So to make this easier for everyone downloading the actions from now on we'll just have 2 versions in the top post, one for 3.x and one for 4.x .
« Last Edit: December 29, 2012, 02:23:29 PM by kiriri »
Best,
Sven

hannibalov

  • Playmaker Newbie
  • *
  • Posts: 10
Re: A* pathfinding (just getting started)
« Reply #16 on: December 16, 2012, 08:15:40 AM »
I'll have a look at the package on monday, but it looks very promissing. Thank you for the wrap up!

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (just getting started)
« Reply #17 on: December 17, 2012, 07:53:48 AM »
alright, I think these 2 should be the last ones missing to make a complete tower defense game:
WillPathBePossible : It checks if, if you were to apply a certain game object to the graph, that game object would block any path from a to b.
IsPathPossible : Is there a possible way between a and b.

WillBePossible was actually hard, since there is apparently no way to theoretically check if a path would be possible. So for now it applies it, and then reverts it after checking if path is possible. This is rather expensive, but oh well, it does work ok if done every frame.

I'll add it to the package in a bit.
Best,
Sven

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (just getting started)
« Reply #18 on: December 29, 2012, 02:22:19 PM »
Instead of making the actions even more complex by adding look at direction, smooth look at, up axis etc pp to it, I simply exposed the direction value now. Save it to a vector3 variable and use a smooth look, lookAt or whatever action you want right after it.

I also added the ability to check if the node closest to a vector3 world coordinate is walkable. It's probably best used with a raycast.
I'm trying to find a way to check if all nodes in a certain area are walkable, but haven't found it yet.

Download the package in the start post.

Have fun ;)
Best,
Sven

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (beta)
« Reply #19 on: January 01, 2013, 12:18:29 PM »
0.6 beta

- update graph area

- check area walkability

- get closest Vector3 on Path

- move to target ignore Y
- follow target ignore Y
- follow Path ignore Y

Best,
Sven

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: A* pathfinding (beta)
« Reply #20 on: January 05, 2013, 03:45:35 PM »
Hi

I've messed around with Hannibalov's follow target action - it's working pretty well for me, except that if the object reaches it's target once then it will stop following and just stand idle.

I have tried making it repeat the follow target action when it reaches its destination, but that makes it walk backwards away from the target, and generally makes it very spazzy


Don't get me wrong, im incredibly thankful for the action - I would've never gotten that far myself lol.. Just some bug feedback :) I have tried to figure out why it stops, but with no luck..

Also, is there any way to change the rate at which it updates it's route to the target? sometimes it follows the same path for 2-3 seconds before it realises that it's target has run behind it in a complete different direction and it will just continue running the wrong way because it doesn't update the path =(

-Koztheboss
Remember, you don't fail unless you give up trying to succeed!

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (beta)
« Reply #21 on: January 05, 2013, 05:59:12 PM »
as for the update, I actually don't know either, maybe I'm just tired though. I'll update the script for the next package.

As for the finish, that is because the path is set to null once the character is less than one waypoint away from the target. Do a search for "path = null;". That should be what's causing the stop I think. If removing that does not work I'll have a look at that too (unless hanibalov reads this first and has the time for it). The basic actions are really supposed to work perfectly by now...
Best,
Sven

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: A* pathfinding (beta)
« Reply #22 on: January 06, 2013, 10:58:36 AM »
Hi Kiriri :) I don't know what happened but as i was testing the game today, the path reset thing was completely gone - All ive done is set the "end of path" event to go right back into the same state and repeat the process, and things are running pretty smoothly now!

I have a different question though, I've used this action for my enemy prefab and it's working great - the only problem im having is that if i set the target object to be a GO variable, it doesn't work at all, like the enemy will not move at all and will just stand still

If, however, I drag-and-drop the player GO to the target then it works no problem - the problem with that is that as a prefab, i can't designate the player as a target without the use of variables which don't work =(

Is there any way to spawn an enemy GO and assign the player as the target automatically now that variables arent working?

Im sorry for asking so many questions, but im not very good at this, and im eager to learn! :)

Thanks for the package btw, it works great!

-Koztheboss
Remember, you don't fail unless you give up trying to succeed!

kolchaud

  • Playmaker Newbie
  • *
  • Posts: 3
Re: A* pathfinding (beta)
« Reply #23 on: January 10, 2013, 07:24:37 AM »
Hi guyz,

Thanks for the great work ! I'm using Follow Target and it works fine on my heavy desktop computer. But on Tablet (A510) and smartphone (One X), the follower is stuck while the target is moving. And when the target is stopped, the follower moves to it.

I'm not sure but I guess CalculatePath method consumes too many resources for mobil devices.
I'm looking for a new way to perform follow target action, if you have any advises, I'll take :)

Thanks

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (beta)
« Reply #24 on: January 10, 2013, 11:34:37 AM »
@Koz
do you have a repro project? I don't have that problem in my own game.  According to your problem it seems to be reasonable though that something must be off in the action, it should not behave so irradically.

@kolchaud
I'll compile my project for Android this evening and try to find out what could be wrong there. Mobile support is very important to me personally too. So far I've ignored it though.

@everyone
sorry for the lack of updates last week. For one I'm back to the classrooms. Additionally new actions become harder and harder to make, at least ones that are useful are. I'm fighting with different problems, like most of the time I'll have to find ways to make the actions work well without using any special object variables, like Path, Node , GridGraph etc.
I think we'll have to use Wrappers in the future, though exposing those in the actions will make them even longer and more unwieldy. I hope this shows the dilemma I'm in. It's Usability vs Functionaliy.
Best,
Sven

Carwash

  • Playmaker Newbie
  • *
  • Posts: 11
Re: A* pathfinding (beta)
« Reply #25 on: January 10, 2013, 06:14:39 PM »
Hi there,

Was pleased to find this addon, but I receive an error when importing the beta package

Quote
Assets/PlayMaker/Actions/Addons/AStar/GetPathLength.cs(64,53): error CS1061: Type `Pathfinding.Path' does not contain a definition for `GetTotalLength' and no extension method `GetTotalLength' of type `Pathfinding.Path' could be found (are you missing a using directive or an assembly reference?)

I've only installed the  AStar Beta 0v6.unitypackage, do I need something else too?

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (beta)
« Reply #26 on: January 11, 2013, 08:26:38 AM »
you need the original pathfinding addon by aaron too (see first post), apart from that you should not need anything more. Did you try restarting unity? Do you get any other warnings or errors?
Best,
Sven

Carwash

  • Playmaker Newbie
  • *
  • Posts: 11
Re: A* pathfinding (beta)
« Reply #27 on: January 12, 2013, 01:01:54 PM »
Thanks for the reply Kiriri.

I already had Pathfinding installed, the error appears after the import of AStar Beta 0v6.unitypackage has finished

I did a restart before posting, after my first one Unity crashed and reset my editor layout :(
No other error messages, though, just the below (same as previously posted)


Quote
Assets/PlayMaker/Actions/Addons/AStar/GetPathLength.cs(64,53): error CS1061: Type `Pathfinding.Path' does not contain a definition for `GetTotalLength' and no extension method `GetTotalLength' of type `Pathfinding.Path' could be found (are you missing a using directive or an assembly reference?)


Edit: On restarting Unity, playMaker fails to load properly (no error messages), there's no PM menus. If I delete this addon and restart, then PM loads again.
« Last Edit: January 12, 2013, 01:10:24 PM by Carwash »

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: A* pathfinding (beta)
« Reply #28 on: January 13, 2013, 02:51:07 PM »
@ Carwash
This is plain weird, I define the function in the same script... It should not be unable to find it. I've just downloaded the package and imported it together with playmaker 1.43 and the latest version of A* into unity 3.5 on windows . The only warning is an obsolete variable, which is not at all bad.
Could you tell me if you still get the error after importing it into an empty project? Else you can just delete the script, it's just an action and not vital.

@kolchaud
Afraid I can repro that on the nexus 10, which has a more powerful CPU than my desktop. I cannot think of a solution as of now. I'm no hardware specialist. If anyone has any ideas, I'd love to hear them. Though my bet is on Aaron's code rather than ours.

@ everyone
I tested and played around this weekend, so no updates this week. I started on node and path wrappers(Though paths can also be gotten by ID). It's making things easier, but even so I'll keep the actions backwards competible, so no worries if you've already used them in a project.
Now I'm tired =_=
Oh and I also would like to encourage everyone to extend this on their own and then post their actions here. I'll likely finish the actions I planned in the first post and then I'll focus on refining it all. Sorry for that, but I just don't have the time to spare anymore and I don't need anything more for my own projects. Hope that's somewhat understandable.
Best,
Sven

kolchaud

  • Playmaker Newbie
  • *
  • Posts: 3
Re: A* pathfinding (beta)
« Reply #29 on: January 14, 2013, 07:21:48 AM »
@Kiriri : Thanks for your feedback. I was able to move multi GameObjects in the same time with MoveToTarget Action. So I don't think Aaron's code is buggy.

In MoveToTarget action, target is set only one time whereas in FollowTarget it's updated each time. I'm going to investigate more on that. If I found something, I'll post here.