The Daily Click ::. Forums ::. Klik Coding Help ::. Path/Grid/Maze Movement
 

Post Reply  Post Oekaki 
 

Posted By Message

lembi2001



Registered
  01/04/2005
Points
  608

VIP MemberIt's-a me, Mario!Wii OwnerI like Aliens!Has Donated, Thank You!PS3 OwnerI am an April Fool
5th September, 2012 at 05/09/2012 16:08:12 -

anyone able to help me with the above style movement?? It is essentially a grid movement through a maze but it can be changed dynamically thus a path movement too???

I am making a Tower Defense style game that you can constantly change the layout of, this means that an engine where there are detectors in place will not work properly. I need to be bale to specify an end point for the enemies and they should be able to get there on their own without getting stuck in walls or colliding with the walls.

Cheers

 
n/a

hapsi



Registered
  13/11/2003
Points
  775
5th September, 2012 at 05/09/2012 19:04:42 -

Isn't there a path finding object? I have never used it though.

 
[Signature][/Signature]

lembi2001



Registered
  01/04/2005
Points
  608

VIP MemberIt's-a me, Mario!Wii OwnerI like Aliens!Has Donated, Thank You!PS3 OwnerI am an April Fool
5th September, 2012 at 05/09/2012 20:02:00 -

I've looked at it but i can't work it out lol.

 
n/a

hapsi



Registered
  13/11/2003
Points
  775
5th September, 2012 at 05/09/2012 20:44:04 -

Check this out: http://www.create-games.com/download.asp?id=7284
It has no readme or explanations but as far as i checked, it worked very well. Space/enter/left-click/right-click.

 
[Signature][/Signature]

Rob Westbrook



Registered
  25/05/2007
Points
  193

360 OwnerVIP Member
5th September, 2012 at 05/09/2012 21:57:22 -

The pathfinding object is a little daunting at first, but once you get it down it's pretty simple!

Basically, you'll want to set the PFO's internal map up to match your game. If you're doing a tower defense I assume it's pretty grid based? At the start of your frame, or whenever your map changes, update the relevant position in the PFO object. setting a square to 0-254 means passable with increasing cost (it will favour the lowest cost path possible), and 255 is impassible. There's even a command that will look at all the obstacle items in your frame and automatically make a map out of it, but I've never used it.

Then when it comes to making enemies move, start a loop through your enemies, set the start point of the PFO to their current square, the destination to... the destination and choose "Find Path". Then in the same loop you can check if they have a valid path, and if so start another loop that will iterate along the path. I believe you have to continually set the enemy's position to the current step of the PFO, then increase the step until the end.

-On loop "loop enemies"
-enemy ID = loopindex "loop enemies"
>set PFO start to (enemy.x / tile size,enemy.y / tile size)
>set PFO destination to (destination.x,destination.y)
>find path

-On loop "loop enemies"
-enemy ID = loopindex "loop enemies"
-PFO path exists
>start loop "trace path" dist times

-On loop "trace path"
-enemy ID = loopindex "loop enemies"
-path is not at its end
>set enemy x to path.x * tile size
>set enemy y to path.y * tile size
>step path forward 1

The only thing is this by itself will make the enemies jump along 1 square at a time, which is probably not what you want. In that case interpolating between the two places should be pretty simple to do.

I hope this makes some sense at all, it's mostly off the top of my head based on how I've done it in the past!

 
There are 10 types of people in the world: Those who understand binary and those who don't.

lembi2001



Registered
  01/04/2005
Points
  608

VIP MemberIt's-a me, Mario!Wii OwnerI like Aliens!Has Donated, Thank You!PS3 OwnerI am an April Fool
11th September, 2012 at 11/09/2012 19:53:07 -

Ok, I have my dunce hat on now and am pleading for help.

Can someone put together a ridiculously simple pathfinding engine for me based on a 32x32 grid? Idiot proof in moron language???!!!

Thanks

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
12th September, 2012 at 12/09/2012 11:41:35 -

It's not ridiculously simple (pathfinding generally isn't), but it might be of some use to you: http://skydrive.live.com/redir?resid=B1E7EE094271BBDA!543
The tricky part with this kind of thing is always going to be optimizing it, so that you calculate paths as rarely as possible - if you tried recalculating a path for every object every frame, your framerate would take a big hit. The example above recalculates a path only when the map changes, and then stores the complete path in an alterable string.

If you're making a Tower Defense game, you might also be interested in this turret AI engine: http://skydrive.live.com/redir?resid=B1E7EE094271BBDA!535

Good luck, and any problems let me know

 
n/a

lembi2001



Registered
  01/04/2005
Points
  608

VIP MemberIt's-a me, Mario!Wii OwnerI like Aliens!Has Donated, Thank You!PS3 OwnerI am an April Fool
12th September, 2012 at 12/09/2012 16:07:08 -

Thank you Sketchy!!! Perfect example and really easy to understand!

Gonna start making my engine now and your example has the features i wanted without me really asking for them.

Thanks again

 
n/a
   

Post Reply



 



Advertisement

Worth A Click