Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Tile based pathfinding for rts,rpg and startegy games.

Author
Message
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 3rd Jan 2010 21:25 Edited at: 6th Jan 2010 01:31
This tiled based pathfinding have 3 levels of terrain to either walk on or avoid.(normal,rough and even rougher)
It also tryes to get as close as possible to target if it cant find an path to the original target.
If it takes to long to search path or it cant find an path so does it simply exit the loop and waits for a new target.
I created this while i whas trying to learn ai coding for path finding.
And its easially done for 3d games with some small changes.
I used the book Ai game engine programming by Brian Schwab when i wrote this.
The neaded media is in the attachement.

NEW HIGHLY IMPROVED VERSION!
left mb to target an tile.
set max tiles and type of pathfinding easy and quickly in code and realtime.




OLD ONE!!!!

Attachments

Login to view attachments
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 3rd Jan 2010 21:28
Screenie.

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Jan 2010 20:24
I'm guessing the rougher terrain has a higher cost and assume it causes the player to cross it more slowly?

Very strange way of indenting code.


> SELECT * FROM users WHERE clue > 0
> 0 rows returned
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 4th Jan 2010 23:44 Edited at: 4th Jan 2010 23:51
Quote: "I'm guessing the rougher terrain has a higher cost and assume it causes the player to cross it more slowly?"

It tryes to find an path with an lower cost as rough and rougher costs more to cross.
But if it finds an path that dont cost so much by crossing them so will it use them.
or have i done something wrong in the code?
If you found an mistake i have done so please help me out
Iam trying to get in to coding again

A while back so whas i working on an rts game that failed,due to the fact that i didt understand the core of ian ms pathfinding routine.(or any pathfinding code )
I actually followed your tutorial
Quote: "Very strange way of indenting code."

You have to show me wath you mean so that i can improve it

And my english spelling sucks i know.



------------------------
In computer programming, an indent style is a convention governing the indentation of blocks of code to convey the program's structure. This article largely addresses the C programming language and its descendants, but can be (and frequently is) applied to most other programming languages (especially those in the curly bracket family). Indent style is just one aspect of programming style.

----------------------
Iam not an programmer so thats why
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Jan 2010 00:33
Quote: "It tryes to find an path with an lower cost as rough and rougher costs more to cross.
But if it finds an path that dont cost so much by crossing them so will it use them.
or have i done something wrong in the code?"

No, that sounds correct to me.

Quote: "ou have to show me wath you mean so that i can improve it"

Well, normally when you write the closing block command (endif, loop, next, until, endwhile) its indentation should match the opening command.

For instance:


It makes it easier to see which code is contained within another block. It also helps you see which blocks have been closed properly. However, the odd part is that I didn't have any trouble reading your code.


"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 6th Jan 2010 01:29
Quote: "It makes it easier to see which code is contained within another block. "

Thats my problem! that iam not an programmer only someone who thinks its extremely fun
I will try to improve it later on

New highly improved code!

Wilf
Valued Member
17
Years of Service
User Offline
Joined: 1st Jun 2006
Location: Gone to Unity.
Posted: 29th Mar 2010 20:02
Hi Cliff,

To try to figure out your code I disabled generation of everything except solids (the barrels) and reduced their number. Any idea why there is such a deviation from a straight-line horizontal path (see attachment)?

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-25 13:50:58
Your offset time is: 2024-04-25 13:50:58