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.

DarkBASIC Discussion / RTS pathfinding

Author
Message
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 9th Jan 2004 20:24
Hey everyone

I'm building a RTS game and so far it works perfect and looks beautyfull... but i dont want units to walk througt the river, but walk over the bridge. The entire landscape is a matrix with a water plain in it as the water level. The water level is 0. So far i programmed that if a unit goes lower than the water level it stops... but i want the unit to walk around the river over the bridge ( a higher part on the matrix) Does anyone knows a pathfinding snippet for this problem???

Juzt a dude who likez progging
Penfold
21
Years of Service
User Offline
Joined: 3rd Dec 2003
Location: RED postbox houses of parliment
Posted: 9th Jan 2004 20:44
Um not a snippet as such but I think I know hows its done.

Create variables for certain points on your map x,z co-ords

then set your units to go to these points using whichever programing means you wish..

you can set up as many 'waypoints' I believe there called so you can get your troops to march between 2 of them or patrol around a building with 4 waypoints I hope you get the idea.

I'm sure there planty of different ways of coding this and I'm sure some nice person will point you in the right direction

Ok so its not a mouse.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 10th Jan 2004 04:09
Ye-ess, Penfold, has the right idea ( although, i don't think it would help much with it hitting the river and stopping )

You need to have the code as you have now, how it stops when it reaches the river. But, you need to add to it.

What you do is you get it's current y-rotation, and find in which direction ( around the y axis ) is the bridge closer ( ie, will the unit have to turn less if it turns right or left? ).

Once you have done that, you need to rotate the unit slightly toward te bridge and then check to see if when it moves next, it will hit the water again, if it will, rotate it a bit more, then keep doing that untill the next move will move it into open ground

( you do all this in one loop, before the sync command. An easy way to check if it's next move will hit is to actualyl move the object, checks it's position, then move it back, and remember this is all before the Sync command, so the player won't see any of this )

Then, after every move, you point the object back at it's destination, then check to see if it will hit the water again, if it will, rotate it around again so it's next move is into open ground.
Keep doing that, and eventually, the unit will move untill it reaches the bridge ( which will mean it won't collisde with the water ) and it will cross it.

You can use this method for anything, such as buildings, rivers, tree's etc, but it won't work very good if teh object the unit is colliding with is moving ( it probably wont' work at all ).

Hope I Helped...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 10th Jan 2004 12:11
Thnx JT! I'm going to try it as soon as possible but now i'm working on resources ... Pretty hard job with lots of animations to handle and things like that... but i'll try it

Juzt a dude who likez progging
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Jan 2004 13:29
Check the codebase for Iam's A* pathfinding. It's as easy to use as it can get. Your water would be marked unwalkable, as would trees and buildings in the map array data. The bridge and grassy areas would then be considered walkable. Run the map search, and your units should go straight to the bridge.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 10th Jan 2004 13:50 Edited at: 10th Jan 2004 14:00
Glad to have helped...

It might take a bit to impliment, depending on your existing code structure, but if you just follow my guide, you should be right...

[EDIT]
Yes, but does it support updated map data... ie, if you add a building, can you then mark that/those map posisions "unwalkable"?
And Besides, I have a dll phobia, I prefer to code everything myself, then I know exactly what is going on... lol.
[/EDIT]


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Jan 2004 14:54
Yes, the map can be dynamic. And it's not a dll either. All DB code formed into a set of functions inside an external DB source file.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 10th Jan 2004 15:02
Ah, ok... well then, I might just have to have a look at it, and see how close it is to my pathfinding routines then eh? lol.

Thanks Phaelax


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 10th Jan 2004 21:00
I saw that thing in the codebase 5 mins ago but i'm working with DBC...

Juzt a dude who likez progging
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 11th Jan 2004 08:11
Ah, well, using my approach should work then.

Also, if you can think it through, you can use my approach as a base, and develop your own wntire pathfinding system, where, instead of it walking up to the water, THEN turning, you can make it just walk straight to the bridge. Good Luck

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 14th Jan 2004 22:54
Jess... i tried my best... but it didn't worked. I tried lots of other ways and nothing works... Sorry... Maybe there is a snippet somewhere, but i only found things for DBPro in the Codebase... If somebody finds something, please post it here

Juzt a dude who likez progging
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 14th Jan 2004 23:18
Make the bridge vary wide, so wide in fact that it covers the entire river lol .

Ok seriously I am also wondering how to do this for I have plans in the future for an rts. If it was me I would just half @ss it and make it so that you just keep cliking the unit to move till it is on the bridg. lol. But thats me.

Alienware area 51/radeon 9800 pro 256mb/sound blaster audigy 2/5.1 surround sound speakers.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 15th Jan 2004 05:43
Hmm... Right now, I don't hae much time, but later tonight, I'll make up an example for you, k?

Sorry, I musn't have explained it properly.
You'll get what I mean when i make the example!

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 15th Jan 2004 21:10
Ok jess i'll hear it when you're finished

Juzt a dude who likez progging
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Jan 2004 04:26
A lot of the pathfinding was written in DBP because of the ability to use TYPES. It made coding the rest a little easier. You could use parallel arrays instead of types if you feel like converting it to DBC.

"eureka" - Archimedes
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 16th Jan 2004 06:13
you can use types in the extended syntax of DarkEDIT, but im not so sure that it would be as good as in DBP

Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 16th Jan 2004 08:24
Types in DBC and DBP are exactly the same, it's just how you declare them that's different...

@Sjakie, sorry about not posting the code... I did it about two hours after I posted, but got side tracked into doing all the stuff for DB Tutor, and forgot all about it... sorry again.

Anyway, here it is;



That should work straight out of the box for ya

Hope I Helped...

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 16th Jan 2004 17:52
Jess... YOU ROCK

I checked out the code and it worked perfectly... I gonna try now to implement it in a test program and then in my game - Can't be too hard . Awesome thankz !!!

P.S. If my game will be finished (if it goes - i hope ) i'll put a special thanks in the credits with your name (just "Special thanks to JessTicular from the DarkBasic forum for giving an example for pathfinding!" or something like that )

Juzt a dude who likez progging
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 17th Jan 2004 09:33
i think everone will be doing that

Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 17th Jan 2004 15:40
@Sjakie, thanks...

@Darwin, I know... lol

Glad To Have Helped...

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Jan 2004 19:16
Not me!
My thx will go to Iam.

"eureka" - Archimedes
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 17th Jan 2004 21:10
Hey jess... newz again

I succesfully implemented the code in my game... I made some drastic changes but it works now with a matrix instead of object collisions and some other minor changes. Thankz again 4 helping me

Juzt a dude who likez progging
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 18th Jan 2004 00:41
that is awsome code JT
i think im going to be using it

Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 18th Jan 2004 05:11
Great! I'm glad that you can both put it to use... Hoorah!

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 21st Jan 2004 18:29
Hey jess... i got it implemented in my RTS game (works damn good man thnx) but theres one thing... the levels are pretty complex and the Pathfinding function makes it sometimes turn the wrong way - in situations like this one:
Here is the unit-> 0
______________ ______________________ END OF WORLD
| | UNITS CANT
water | | water GO TO HERE
| |
| |
______________| |______________________
And it is targeted to here-> 0

And what is the unit doing then? Yes... it walks to the right
out of the landscape. I already programmed something that if the unit
exits the World they simply turn around and choose the other way. But i don't like that! That looks so stupid! (ow yeah BTW... i dont use pointing at the nearest walkable area because that doesn't fixes my problem, and my landscape is way too complex for that - Instead i programmed something that works with positions and then calculates the path). And now i'm trying to make some code that tests both paths before choosing one, like this:

1 Try path 1 and count length (turn left)
2 Try path 2 and count length (turn right)
3 Check wich path is shortest
4 Set direction to the shortest path

and if a path ends in a place out of the world, the other path is automaticly chosen.

I tried programming it but it doesn't work
Maybe you can try it jess... I'll try to attack the problem tonight but i dont think i'll solve it...

Juzt a dude who likez progging
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 22nd Jan 2004 12:57 Edited at: 22nd Jan 2004 12:59
I assume that you wanted that diagram to lok like this:



A quick fix would be to make plains that go from where ever the unpassable areas are at the edge of the world, right out to the length of the world again. ie;



But that's not a real way to fix it...

I'm not too sure how you would do it, unless you set up a full-on pathfinding system that actually calculated the direct path to take from the very start using a walkable/unwalkable grid that you set up ( not a physical grid, an array holding all the information about the landscapes etc that says ground(5) = 1 where 1 means walkable etc, then you check through that in your path finding code to see if you will walk off the side of the world [ which would be all marked as unwalkable ] so that means that path is not viable, so you must take the other path ).

This is called an A* Pathfinding algorithm. I think there's one available in the CodeBase, if you wanna have a look.

Sorry I'm not much help on this, as I have never programmed this much pathfinding before.

Hope I Helped...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 22nd Jan 2004 15:20
Ok jess... too bad

But im workin on it and it seems to work... not 100% allright but i'm tryin my best. Maybe i can do it myself

Juzt a dude who likez progging
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 22nd Jan 2004 15:42
Thats the spirit!

Glad To Have Helped This Far...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 22nd Jan 2004 20:02
Guess what jess... IVE DONE IT

I'm bouncing around in my room with my guitar in my hand because im so happy now!

I modified your code in this way:
-1 check if unit needs a path (because it hits the water)
-2 left or right( you did this with an angle check, but because some paths are impassable (because they're leading the unit out of the world), and i wrote some code that checks BOTH paths and walk on them untill they reach the target. Now the function calculates the shortest path (or the path that works) and chooses that one.
-3 the unit moves to its target.

This works on all kinds of landscapes and even with a lot of impassable terrain, it still keeps working

Thanks 4 helping me so much jess I could never do this on my own

Juzt a dude who likez progging
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 23rd Jan 2004 04:40
Hey,

Good on ya.

Just out of curiosity, can I have the modified code? So that I can see exactly what you did, and I may even be able to make it more efficient or somesuch thing ( but, mainly, I want to see how you did it ).

Glad to have helped yet again.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Travis
21
Years of Service
User Offline
Joined: 9th Nov 2003
Location: West Aust.
Posted: 23rd Jan 2004 04:57
yay its 'glad i helped!!!' as opposed to 'hope i helped...'
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 23rd Jan 2004 09:56
I need to make some little changes and then ill give it ok?

Juzt a dude who likez progging
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 23rd Jan 2004 17:38

some changes are made... if you need help, just ask

Juzt a dude who likez progging
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 23rd Jan 2004 19:53 Edited at: 23rd Jan 2004 19:54
Works great, but their are still minor glitches:
the unit will follow the line (x = impassible)




Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 23rd Jan 2004 20:41 Edited at: 23rd Jan 2004 20:49
@Emperor Baal - You mean it walks out of the landscape or just the wrong way? BTW... DONT click in the holes, wierd things may happen...

I bet yer gonna use it in DarkTIMES dont you? Can you put me and JessTicular in the credits list please? I'd like that

Juzt a dude who likez progging
MikeyP
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: Manchester, UK
Posted: 23rd Jan 2004 21:29
Right i only read half the thread so if someone has said this sorry! But, if you say the water is a plain, simply get the plains y position and on you moving function or code simply check to see the user isn't going to go below that value Tis what I do lol
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 24th Jan 2004 00:42
Ah, Sjakie:
Quote: "I bet yer gonna use it in DarkTIMES dont you? Can you put me and JessTicular in the credits list please? I'd like that"


I've coded something "better" using cos and sin. No weird movements and all. So I'm not gonna use it


Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 24th Jan 2004 10:33
@ Demonsbreath - That IS what this code is doing!

@ Emperor Baal - Can i get code???

Juzt a dude who likez progging - Me loves RTS games
AluminumPork
21
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 24th Jan 2004 10:49
Wow, I was browsing and found basically what I've been looking for. Thanks alot!

P4 2.4Ghz HT, 512MB RAM, ATI Radeon 9600 128MB, 19" Viewsonic, 80GB HD, 48x12X48 CD-RW, 16X DVD-ROM

http://www.frostyle.com
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 24th Jan 2004 12:26
Glad to hear my code is succesfull

Juzt a dude who likez progging - Me loves RTS games
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 25th Jan 2004 12:09
Problems with the pathfinding!

My river has now pretty rough shorelines. Looks ok, but the pathfinding doesnt like it. It gets stuck sometimes. Is there anyone who can try to fix that problem. Im going 2 work on it too...

Juzt a dude who likez progging - Me loves RTS games
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 26th Jan 2004 05:14
just make the computer think that the river is straight, altho it isnt
ie:
computer thinks it looks like this: (Xs are unwalkable)

altho it looks like this, to humans


you know what i mean?

Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 26th Jan 2004 11:42
@Sjakie... Ahem... that's my code too, lol.

The way you find the shortest path is a really inneficient way of coding it. ( your code isn't inneficient, just the method )

I know that it's probably the only way to do it in DBC, but what you really need to do is to be able to calculate the path without having to actually move the unit, 'cos if you think about it, if you are trying to pathfind 100 units, plus 100 AI units all at the same time, your FPS will drop to about 2. lol.

I'm not too sure on how to do it myself ( I would have done it the way you did it too ), but there's gotta be a better way...
Hint, Hint @ Emporer... lol.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 26th Jan 2004 16:38
Well, for a start, here's a way to do it, get the distance that the guy should walk. Make an array(99,1) and divide the distance with 100. Put some coordinates in the array, using cos and sin to place them, and a get ground height or tile check to check if its impassible.

Then, a little ascii



You can do 2 checks, with sin and cos. If the next waypoint cannot be placed, then you can increase the angle for the next waypoint (first) or decrease it (second)
This way you can get multiple routes for the guy



Then check which way is the shortest, and make the guy follow the shortest way!

I hope that you understand my terrible art


Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 26th Jan 2004 16:58 Edited at: 26th Jan 2004 17:00
Im just 14 years old... I know how the Tangent works, but what da hell is Sin and Cos??? The only thing i know is that u can get some wave pattern with them, but thats not useful 4 pathfinding, or am i wrong? Plz explain...

@ darwin - Come on, thats cheap! And doesnt work well when there's a diagonal river!

@JessTicular - Yes i know its slow, but at least it works (sometimes)

Juzt a dude who likez progging - Me loves RTS games
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 26th Jan 2004 17:43
@Emperor Baal, Yeah, that is a fair bit better than Mine and Sjakie's method

@Sjakie, Hmm, Trigonometry is a tricky one if you've never used it b4...

ok, I'll try an explain a simple version...



In that ( shocking ) diagram above, you can see how the adjacent side ( adjacent means "next to" ) is next to "theta", and the opposite side is opposite "theta".

In a right angled triangle, the hypotenuse is always the longest side, and is opposite the right-angle.

Now, we can use Sin() and Cos() to find the length of any of the sides or the angle of "theta".

To find the angle of "theta",
theta = sin(opposite/hypotenuse)
or
theta = cos(adjacent/hypotenuse)

To find teh length of the sides, I can't quite remember the syntax at the moment, but I'm sure Emporer Baal will enlighten us.

Hope That explained it a bit for you...
Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 26th Jan 2004 18:27
Sine and Cosine are extremely important, without them, you won't have 3D. Imagine, you have a cube, and you want to have a camera behind him (20 units). Then we can use sine and cosine to place the camera.



You can read all about sine and cosine



@ http://mathworld.wolfram.com/Sine.html


Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 26th Jan 2004 21:43
Doesn't seem too hard. Maybe my dad can explain it to me a bit more. But uhm... maybe this seems to be silly... but i can use the Tangent too? I mean, i completely understand Tangent, maybe thats easier 2 me...

Juzt a dude who likez progging - Me loves RTS games
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 26th Jan 2004 22:02
Well, it can be used, but not for 3D rotations and positions (get a calculator and type: tan 90 )



Ik weet dat het moeilijk is, dat tekenwerk is ook moeilijk! AHH!!


Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"
Sjakie
21
Years of Service
User Offline
Joined: 17th Dec 2003
Location: Netherlands - Delft
Posted: 27th Jan 2004 16:18 Edited at: 27th Jan 2004 16:25
Yeah i know that.. you get a error!

But in DB theres also a AtanFull(xdistance,ydistance) command wich i can use... but maybe i can learn the cos and sin

I think i know how to do it, it must be something like this:


I think i need to do it that way...


@Emperor Baal - Het is zeker moeilijk! Maar ik ga gewoon klooien tot het lukt stop maar met tekenen dat is gewoon k*t (For others: This is Dutch!)

Juzt a dude who likez progging - Me loves RTS games

Login to post a reply

Server time is: 2025-05-23 04:00:12
Your offset time is: 2025-05-23 04:00:12