Sequential Grid-Based Movement

Get help using Construct 2

Post » Sun Aug 11, 2013 7:17 am

This is an extension of Tile Movement, except instead of moving one-by-one based on player input, the idea is that there is a single player input (the destination) and that the object needs to move there in a grid-based fashion (one space at a time).

Take for example this image:



Every bright tile is one that the object can move to. Suppose the player clicks the bright tile at the far right (3 spaces to the right of the purple object). The idea is for the purple object to move to the clicked tile, one tile at a time until it gets there.

Does anyone have a good idea on how to accomplish what I'm trying to do?

BoardGame.capx

Currently I have a pathfinding object that will move from the selected object to the destination tile, 'tagging' tiles that it overlaps on the way there. Once it reaches its destination, the object will then move one space at a time through the tagged tiles until it reaches the destination.

However, my pathfinding object never reaches its destination:



Anyone know why?Excal2013-08-11 10:45:52
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,224

Post » Sun Aug 11, 2013 11:22 pm

I'm able to get the moveFinder to arrive to the destination now.



I've checked in the debugger, and the tiles the moveFinder passes through on its way to the destination definitely are getting 'tagged'. Now it's just a matter of figuring out why the program never moves:

Excal2013-08-12 04:26:47
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,224

Post » Mon Aug 12, 2013 4:16 am

Another issue I encountered during testing - obstacles aren't being set up properly.



The pathfinding object goes through a space that is not allowed.



Not sure why this is. Are invisible objects capable of being obstacles?Excal2013-08-12 04:24:47
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,224

Post » Tue Aug 13, 2013 7:21 pm

Here is one way to do it:

Boardgame movement

I used pathfinding and moveTo plugin (you'll need to get it to check this out).

Edit: Fixed the example a bitvee412013-08-13 19:35:56
B
24
S
9
G
7
Posts: 756
Reputation: 7,292

Post » Thu Aug 15, 2013 7:16 am

Created a tutorial based on this .capx, explaining things a bit more. Check it out! :)vee412013-08-15 07:16:55
B
24
S
9
G
7
Posts: 756
Reputation: 7,292

Post » Thu Aug 15, 2013 7:28 am

@vee41

You are my hero :)
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,224

Post » Fri Aug 16, 2013 5:17 am

@vee41

Is there a way to make the object pause at every square? So instead of gliding to the destination, it makes a slight pause at every square.

I assume this means that every square on the way to the final destination will need a marker, and that the object will need to pause for a second each time a marker is destroyed.

Also, I'm having programs move off the grid for some odd reason, along with multiple marker points being generated in some strange spots.


Excal2013-08-16 05:34:45
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,224

Post » Fri Aug 16, 2013 6:29 am

I'm noting this topic, do you feel it has pac-man clone potential?
B
15
S
5
G
2
Posts: 164
Reputation: 3,082

Post » Fri Aug 16, 2013 6:35 am

For a pac-man clone, basic pathfinding with walls as solids should work.

This is more or less an intermediate to advanced application, since each object has to account for other objects being in the way.
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,224

Post » Fri Aug 16, 2013 6:58 am

Few ways you could approach that:

1) Think I did breadth first search in similar situation one time. It replaces the standard pathfinding (which did not exist when I did this). The general idea would be:

- Create an array where each square has a value
- Give the start square value zero, and call a function that checks if squares next to it can be moved. The function gives those squares value one in the array, and calls itself for surrounding squares. Those squares are given value two, and they call surrounding squares etc.
- When the function hits the square we want to travel into, it stops executing.
- Now, we check the 'route' in the array we have built this way. From the square we want to travel to, we trace our steps back to the square one using the route of descending numbers. This is the shortest route.
- We generate the go to markers to each of those squares.

2) Stop the movement at center of each square for a second whenever arriving in new square. This is probably the easier way. :)

3) You could make the moving object pause always after certain distance traveled. This distance would coincidentally be the same as distance between two squares.
B
24
S
9
G
7
Posts: 756
Reputation: 7,292

Next

Return to How do I....?

Who is online

Users browsing this forum: ivanski1983 and 12 guests