Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 18th Jan 2012 20:10 Edited at: 19th Jan 2012 17:47
ok so i am making going to try to make a kind of RTS / Tower defence where i would need to have fairly good pathfinding.

because the enemies are zombies, the pathfinding doesnt need to return the shortest possible path but it as long as the route is fairly fast it should do.

Also the map im going to use will only have fairly large and rectangular obstacles so the pathfinding system wont have to face extreme mazes.

so what i would like some kind soul to tell me is what problems are there in my code and what could i do to make it work better?

i have this code here :



it is a working example wich i made, but it sometimes chooses quite odd paths and doesnt work 100% of the times.

change the variable node_difficulty to change obstacle count, dont try lower that four, wont give you good results

OH and it uses advanced 2d for drawing


below is the uglier slower and more booring (but working) code without advanced 2d




oh and here is am image that demonstrates the weaknesses of my code

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th Jan 2012 21:46
Hi noobnerd


I flew over your code and then noticed that I don't really know much about pathfinding What I can do is link you to an excellent pathfinding DLL : http://forum.thegamecreators.com/?m=forum_view&t=114240&b=5

I used it before in an RTS game I started once, it's incredibly fast The best part is you can compile the path to waypoints which is very efficient.

TheComet

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 19th Jan 2012 03:32
I think if you're using dark AI or LUA scripting, you will find it easier to create path finding and intelligent design. (dark AI is the best)
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 19th Jan 2012 07:01
Im looking into this soon too... if this thread is still active I will try to post my findings back here...

noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 19th Jan 2012 16:22
thank you all

@TheComet : looks really effective! but as i do this mostly for learnig purposes id rather like to learn whats wrong with my code or just learn a good way to write my own pathfinding code, even though that plugin probably is always going to be faster and more accurate.

@Basjak : i dont have dark AI and i dont know what LUA is but might just check it out if its free?

@MRValentine : thanks!
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 19th Jan 2012 17:42 Edited at: 19th Jan 2012 17:46


this code is lightly better, but i changed the settings as to more efficiently demonstrate the failures of this code...
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jan 2012 01:52 Edited at: 21st Jan 2012 01:53
Since I don't have the advanced 2D plug-in I tried your "working" version which doesn't use it. It crashes every time as soon as I click anywhere on the screen. Am I doing something wrong? What should I do when I get the initial maze plan?

The error I get is "Runtime error 118 - array does not exist or array subscript out of bounds at line 107" which in my copy is



However, after a bit of experimenting I managed to see how to get it to work. As you say most of the time it finds a sensible route (certainly good enough for a zombie ) but I could easily get it create a strange path by forcing the start and finish points to have an open box like barrier between them as in the fragment example below:



Haven't studied the code yet but it looks as if the backtracking has gone wrong (assuming there is any ). I changed the colours so I could see the path easily.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 21st Jan 2012 05:27
WoW... Fortjnately for me non of my projects so far appear to require a pathfinding system... I could be wrong... do RPG's in any way require them?

Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 21st Jan 2012 10:30
I suggest you take a look at A* (Astar). You can look it up yourself internet and the code base here has examples, I'll also dig up my working reference for example, give me a few.

Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 21st Jan 2012 14:50 Edited at: 21st Jan 2012 18:26
I use this Astar function form my projects takes a bit to fully understand what is all going on but it's actually quite simple. The way I understand it works:

I wouldn't blame ya if you find this confusing.



Anyways here's the working example of codes taken right out of my own projects.
Controls:
L-Click: Place walls
R-Click: Erase walls

L-Click + (1)Button: Set the START location
L-Click + (2)Button: Set the GOAL location

(R)Button: Reveals the Rate values
(D)Button: Reveals the Dist values
(C)Button: Reveals the Cost values

Returnkey: Astar Pathfinding





Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jan 2012 18:04
Very neat. Nice demo.
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 21st Jan 2012 18:36 Edited at: 21st Jan 2012 18:42
@ Green Gandalf : yeah i forgot to mention that you must place the goal before you place the start but im glad you got it working na reccomend you download advanced2d cause its awesome

@Ashingda 27 : Really nice! and the vast amounts of REMs !
really explaining i got it all in i will now post the new version of my code, quite similiar to yours but it is integrated to my arrays etc. THX

Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 22nd Jan 2012 02:27
Glad you were able to take it all in. Ran your codes it works well are you planning on having multiple zombies use their own waypoint paths? There's different ways to go about it if you are.


1. Can make the function construct the waypoint of the individual zombie path directly in the function, may need to add a variable to the function to know which zombie's array to affect.

2. Do it the exact same way you have now, just after calling the function simply copy the built waypoint to the selected zombie path array.

noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 22nd Jan 2012 10:44
yes, i will have multiple zombies and i have already implemented the second way there, i copy the waypoint array that the Astar function creates to the zombies own waypoint array.

i am currently trying to do an waypoint optimizer that would remove "unnecessary" waypoints, that is if yo have 5 points in a row the midle three will be unnecessary.
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 22nd Jan 2012 11:05


here is a quick example with 5 zombies
Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 22nd Jan 2012 12:21
Very nice example and good progress. Keep in mind if the target is moving, the zombies will have to keep searching for a new waypoint. Dont worry about Astar effecting the processing performance, it's quite fast unless your map size is gigantic like 10000x10000 or so. Just don't perform Astar every loop. Check it once in a while, give it a wait timer or only check it once for every zombie after they completed moving one space that's the only real time they need it, to know where to go next.

Login to post a reply

Server time is: 2026-07-09 20:55:06
Your offset time is: 2026-07-09 20:55:06