Quadralant Path-finding Optimization? [SOLVED]

0 favourites
  • 11 posts
From the Asset Store
Use this game pack to create your own game, modify the existing game or simply take a look and see how it was made.
  • I have successfully created a system for path-finding in Construct 2 for my game Luna. Whereas the second player can successfully follow you through the level with ease. However, I need help optimizing the code. The method I use utilizes a lot of IF statements since I cannot hard code a reference to an instance variable. This method will be of interest to a lot of people I am sure.

    The theory that I exercised was that by using a series of quadrants and then measuring the distance to Player1 and Player2 you could read the direction of how to get to the quadrant that is nearest Player1 by reading the instanced direction from the quadrant closest to Player 2 (Similar in theory to a DNS lookup)... Well this worked splendidly!, but I just need help optimizing the IF statements.. so that I don't have to use a bunch of IFs. Thanks for looking and enjoy using this method I created in your own projects!

    <font color="RED">I have commented the code where I need help. ( UPDATE 11.29.2012 SOLVED! )</font>

    Download Gillis CAPX Example File <- My original file

    Download R0J0hound optimized CAPX Example File

    <font color="BLUE">Watch the Female Character for an example of my Quadralant Path-finding in use!</font>

    [TUBE]http://youtu.be/Q76_-8xWVOs[/TUBE]

    Thanks for looking

    Dan

  • bump :)

  • So the Quad objects need an instance variable for every Quad? It works but I could see how it would be a bit time consuming to set up.

    You could just use one text instance variable and store a comma seperated list of the values.

    So for instance the top left Quad would have a "list" value of "2,2,2,2,2,0,1,1,1,1". Then events 12 to 21 could be replaced by one action added to event 11:

    player2| set direction to int(tokenat(Quad.list, player1.ClosestQuadName, ","))

  • That is an interesting concept. That is a pretty huge re-write for me unfortunately. I am hoping that I can simply rewrite the IF part.

    ...and yes. Quad objects need an instance for all other quad objects. Right now, for example, there are 82 quads in level 1 of Luna. I used the quad system for Player2 and enemies. Each quad knows the direction to all other quads. I can even use it for story events if I want Player 2 to lead and I follow. Pretty effective but a LOT of work to wire up

    Thanks for your idea. I might mess around with this if no one can directly solve my IF issue.

  • There's no dynamic way to refer to different variables with one action. Condensing them into one var like r0j0 said is pretty much the only way.. or you could use an array I guess but that's probably even more awkward.

    Have you looked at the A* pathfinding plug in?

  • I have tinkered with (A*)Node Pathfinding in the past and have not been impressed with the static rail feeling. I like the variance that I get from my "Quad Model". I will put tinkering with A* in Construct 2 on my todo list but I am hoping I can optimize my Quadralant Path-finding theory as it is working.... it's just that the code gets a bit messey. I am happy with how it works now, just unhappy with the hundreds of lines of extra unnecessary code.

    Thanks for your input!

  • You can still use my list variable suggestion as you have it now. Just add a "list" variable and populate it from the other variables.

    +Start of Layout

    Quad| set list to self.Quad0 & "," & self.Quad1 &...

    The A* algorithm could also be used and it would have the same result. It would take longer to compute at runtime but the only setup needed would be to list what quads are connected, which is faster to do than manually setting directions from every quad to the other imo.

  • OK. I will check this out tonight. It would be killer if you could upload a modification of my capx for an example? :) :) I would be forever grateful, but I will check it out tonight.

  • Here is a capx:

    http://dl.dropbox.com/u/5426011/examples16/QuadralantOptimised.capx

    Unfortunately I don't have time to do a astar example at the moment.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you so much. I will mess with this tonight. :D <img src="smileys/smiley32.gif" border="0" align="middle" />

  • R0J0hound. That worked like a charm. It seems to work a lot faster now too. Thanks for your help!! This is so cool!!!!!!

    Marking Thread solved!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)