The Daily Click ::. Forums ::. Klik Coding Help ::. obstacle pathfinding moves?
 

Post Reply  Post Oekaki 
 

Posted By Message

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
18th August, 2009 at 18:54:22 -

I have pathfinding in two segments of the game. But in one i want to make it different.

Basicly it is a turn based pathfinding. So you click a tile within your range and go there. And the tiles within range are shown.

I have the range and the obstacles set up. Now what is bugging me how would i show the farthest tile the unit can go if the tile is really close but the unit needs to go around obstacles? Basicly the unit cannot go around so much, but since it is in range it shows like it can. And that doesnt really affect much but its confusing. since it should only show the possible moves.

Should i loop to find path for all possible steps or is there another way to do it, since im quite confused.

I am using pathfinding object.

 
Code me a sausage!

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
18th August, 2009 at 20:31:43 -

What? That wasn't very clear

Are you just trying to highlight the tiles within reach of the selected unit?
Like this: http://wiimedia.ign.com/wii/image/article/832/832368/fire-emblem-radiant-dawn--20071102020851742.jpg

If so, you will have to use a fastloop to check each tile individually, to see whether it can be reached. To save a bit of time, you only need to check for paths to the tiles that are within normal range (ie. if there are no obstacles anywhere).

 
n/a

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
18th August, 2009 at 21:19:31 -

Yeah, i figured it out, but it takes quite a long time to do it. I should try to make it a little faster, i am using two loops, and surely i could use only one to do it, or atleast to separate them.

Thx anyway.


Edited by Don Luciano

 
Code me a sausage!

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
18th August, 2009 at 21:58:03 -

Well i finished it. Its quite okay... so if anyone is interested in looking it i have uploaded it.
Here is the link.

http://www.mediafire.com/?azvtnzmznzg

I didnt do unit obstacles and loop for obstacles and it loops all blocks... but i since already have those stuff in my project and i did this separatly from it.


 
Code me a sausage!

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
18th August, 2009 at 23:25:58 -

Hmmm... That's strange.

I can run it okay, and I can even open it up in the Event Editor - but every time I try and open it in the Event List editor, it just crashes MMF2

 
n/a

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
19th August, 2009 at 13:16:44 -

That is strange
maybe because of extension? or mmf version

 
Code me a sausage!

~Matt Esch~

Stone Goose

Registered
  30/12/2006
Points
  870

VIP Member
20th August, 2009 at 23:53:27 -

Your code doesn't wrap the view around objects properly. There are parts which you can potentially get to based on your square grid that you don't show. I just wrote my own example and it produced results looking like this:

Image

It's quite a bit more complicated and takes a little while to work. Path finding type problems usually take a little while and my implementation is inefficient because I am not able to add objects to a list (which means iterating over all of the objects numerous times - a square complexity O(n^2) ). The best way to solve this problem is to do it in stages per codeloop, so that the screen can refresh. Do 1 iteration per codeloop or something. I will release my code at some point.

 
http://create-games.com/project.asp?id=1875 Image


Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
21st August, 2009 at 02:03:58 -

The problem there is that the vision range is not fixed - it varies between 5 and 7 squares.
In a lot of cases (incl. any strategy game) that's not good enough - for movement or vision.
It does have the advantage of being more circular, rather than diamond-shape, so it would be better in some cases.

This kind of thing is easy in MMF1, using the "Grid" extension, but in MMF2 it seems to be more difficult.
The "APF" extension is more powerful, but makes everything very complicated - even a basic example takes lines and lines of code.
The "Pathfinding" extension just doesn't seem to work for me - even opening the example files causes MMF2 to crash.



Edited by Sketchy

 
n/a

~Matt Esch~

Stone Goose

Registered
  30/12/2006
Points
  870

VIP Member
21st August, 2009 at 11:53:27 -

My example uses a user-defined VisibleRadius property, so each of those blue player objects can have a variable visible radius. The grid is generated using that property for each of those obejcts. In this example each player has his own grid but in practice I would use a single grid of the largest user-defined radius and use this for all players.

 
http://create-games.com/project.asp?id=1875 Image


Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
21st August, 2009 at 14:51:55 -

That's not what I meant.

Suppose a unit can move 5 squares per turn.
Your method is showing squares as being reachable, when they are not.
Or, supposing a unit can move 7 squares per turn - then you are not showing squares as being reacable, when they actually are.
Image


Now, if your method is actually for calculating the line-of-sight, and not movement-range, (as I suspect is the case) then it still doesn't work properly.
The spaces marked with a red "X" should not be visible.
Image

 
n/a

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
21st August, 2009 at 18:16:29 -

"Your code doesn't wrap the view around objects properly."

I dont know what you meant by that, but it does wrap the view around objects properly. It is exactly what it does. And yours does not. as you shown in the example.

And if you wanted to do line of sight you didnt do that aswell... as sketchy sketched it out for ya.

And that oval thing can be achieved easily by just adding to the loop to compare distance to maxsteps*gridblocksize


Here: http://www.mediafire.com/?mjzron0zztz

Next time matchs you should keep your stupid comments for yourself.

Edited by Don Luciano

 
Code me a sausage!

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
21st August, 2009 at 20:10:14 -

I'm not sure you needed to be quite so harsh - I think he probably was trying to help...

 
n/a

Don Luciano

Heavy combat pancake

Registered
  25/10/2006
Points
  380

VIP Member
21st August, 2009 at 22:21:09 -

yeah probably... sry mate.

Anyway the stupidiest thing is, that i made this code for my main project, i now merged it in. And it doesn't work. The game crashes. And everything is the same, i checked everything to find why it crashes but there is no reason at all. I copy pasted, changed the objects, checked the loops, spreads, and everything should work. But it just doesnt.

 
Code me a sausage!

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1969

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
22nd August, 2009 at 00:48:45 -

I made an example of a pretty simple and efficient system, using the pathfinding extension.
It only uses one fastloop, and only checks the squares within the normal movement range.

http://cid-b1e7ee094271bbda.skydrive.live.com/self.aspx/Public/Pathfinding.mfa

If you have trouble getting it to work, then you could send me your pathfinding.cox and I'll make it work with that - I think maybe we have different versions or something.


 
n/a

~Matt Esch~

Stone Goose

Registered
  30/12/2006
Points
  870

VIP Member
22nd August, 2009 at 03:05:06 -

Don Luciano.

Line of sight is clearly not what was achieved from the example I looked at. It actually gave some squares you would cross out as was done so in a previous post. I could only assume that you would want to display the attainable square (i.e. a square that a path exists for). So evidently the squares that you can see are places that can be reached within the specified radius and would test line of sight to those positions independently (i.e you wouldn't attempt to go to a destination that you couldn't see, even though there is a possible path for it). If you are just interested in a region available in the line of sight then that's just an additional restriction of the grid I am displaying. Basically what that means is: you should keep your retarded comments to yourself.

Sketchy

The code that limits the visible region is a single condition. Combine this with the 2 loops that actually create this grid then theoretically I can make the region any shape I want. In the case of N moves, the limitations are based on the sum of the x and y indices rather than the sum of the square of the indices. My example would then restrict the grid to just the squares that a path within the region exists for, and then you could restrict this further by any other condition i.e. line of sight. Having said that, I would expect that visible sqaures are a subset of the path-reachable squares. Depending on how you want to implement this though, having a set of squares representing the reachable squares within x moves is useful given that this is player controlled. If you can see the position then it doesn't matter that the player cannot. I can imagine that for some enemy AI purposes you would only want to get the squares visible to the enemy object.

Granted MMF is not very good at doing this kind of stuff. The pathfinding object sounds like a good idea.

Edited by ~Matt Esch~

 
http://create-games.com/project.asp?id=1875 Image

   

Post Reply



 



Advertisement

Worth A Click