Quadralant Path-finding Optimization? [SOLVED]

Get help using Construct 2

Post » Wed Nov 28, 2012 8:15 pm

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!

I have commented the code where I need help. ( UPDATE 11.29.2012 SOLVED! )
Download Gillis CAPX Example File <- My original file
Download R0J0hound optimized CAPX Example File

Watch the Female Character for an example of my Quadralant Path-finding in use!
[TUBE]http://youtu.be/Q76_-8xWVOs[/TUBE]
Thanks for looking
DanGillis2012-11-30 02:32:57
Image
B
35
S
13
G
9
Posts: 142
Reputation: 7,340

Post » Thu Nov 29, 2012 3:07 am

bump :)Gillis2012-11-29 03:07:23
Image
B
35
S
13
G
9
Posts: 142
Reputation: 7,340

Post » Thu Nov 29, 2012 9:57 am

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, ","))
B
79
S
24
G
54
Posts: 4,754
Reputation: 40,771

Post » Thu Nov 29, 2012 3:13 pm

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.Gillis2012-11-29 15:17:20
Image
B
35
S
13
G
9
Posts: 142
Reputation: 7,340

Post » Thu Nov 29, 2012 3:23 pm

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?
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Thu Nov 29, 2012 4:40 pm

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!
Image
B
35
S
13
G
9
Posts: 142
Reputation: 7,340

Post » Thu Nov 29, 2012 5:06 pm

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.
B
79
S
24
G
54
Posts: 4,754
Reputation: 40,771

Post » Thu Nov 29, 2012 5:31 pm

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.Gillis2012-11-29 17:40:42
Image
B
35
S
13
G
9
Posts: 142
Reputation: 7,340

Post » Thu Nov 29, 2012 7:12 pm

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.
B
79
S
24
G
54
Posts: 4,754
Reputation: 40,771

Post » Thu Nov 29, 2012 7:24 pm

Thank you so much. I will mess with this tonight. :D
Image
B
35
S
13
G
9
Posts: 142
Reputation: 7,340

Next

Return to How do I....?

Who is online

Users browsing this forum: onzephyr and 23 guests