Posted: 7th Mar 2003 18:06
ok, whenever this topic comes up and i explain to people about my views, they all say it's too stressful or to much to do, thought it was time i explained how easy it is.

my idea was to divide your building into strategic points, (maybe similar to what they do in some industry games) using these points you could navigate your character from position a to position b withought them passing through walls.

i had a presentation to do rescently for which i had to come-up with pathfinding code, i spent a couple of minuts coming up with the code, probably a couple more refining it so it could be understood and here it is:

http://www.realgametools.net/forums/attachments/path_finding.zip
Posted: 7th Mar 2003 19:26
Cool,

I used A* pathfinding for Lode Runner, since that's what they used in the original.
Posted: 7th Mar 2003 20:10
have you got a game demo out? would really like to see the A* algorithm in action ^_^
Posted: 9th Mar 2003 1:57
Sure, if I win(retro comp), everyone can benefit from my source for A*
Posted: 9th Mar 2003 2:52
why is path finding so difficult? way i see it (mind you i havent coded it) theirs 2 ways, the caterpiller that just follows the players movments to follow him, and wayponts where you set markers on the matrix and the ai simply takes the shortest route between the 2 poinnts, if collision is good the worse result is you have ai running into a walll, litterary, but if the waypoint are player set thats only their fault.
Posted: 9th Mar 2003 2:58
If you've played MOH sometimes you will see someone magically bypass you and land up the stairs on a second floor - amazing!
Posted: 9th Mar 2003 3:11
well what do you expect, he was taught by mario....dem powerful legs
Posted: 9th Mar 2003 3:38
path finding is very simple to think about but complex to code! although this method is easy and took me minutes to code up, i bet it'll take sometime to understand the code, but when you do it'll all be so obvious to you ^_^
Posted: 9th Mar 2003 14:28
Howabout someone puts the a sample code on this forum?
Posted: 9th Mar 2003 20:27
sorry if it doesn't come out well, the code required a house.x object, you can download the entire program from the link on the top of this page (my first post!) if you find any difficulties in understanding the code just give me a shout and i'll be glad to xplain ^_^

+ Code Snippet
Rem * Title  : First Person Camera
Rem * Author : DBS-LB
Rem * Date   : 1st Sept 99

	remstart -----------------------------------------------------------------
	
	athr: hexgear
	code: pathfinding

	note: this just shows a very easy method of pathfinding, can be applie to
			many types of games, e.g. commandos 2, if your man is in the sitting
			room and you click the mouse for him to move to the bathroom, the
			algorithm gets him to the bathroom then he makes his way to the 
			clicked point withough passing through any walls, hope it helps.

	house plan showing key rooms/points

	9 - bathroom.
	4 - sitting room.
	7 - bedroom.
	2 - kitchen
	5 - corridor

	1,3,6,8 - connection points
	__________________________________
	|				|							|
	|				|							|
	|		9		|        4				|
	|				|							|
	|_____  ____|________  __________|
	|											|
	|		8	 6		  5   3    1		|
	|_________  _____________  ______|
	|				 	|						|
	|					|						|
	|			 7		|			  2		|
	|					|						|
	|______________|_________________|

	remend -------------------------------------------------------------------


rem settings 1
	set display mode 1024,768,16
	hide mouse
	sync on
	sync rate 50
	autocam off
	set camera range 1,200

rem images
	load image "floor.bmp",1

rem the matrix
	make matrix 1,100,60,10,6
	prepare matrix texture 1,1,1,1
	update matrix 1
	delete image 1	

rem objects
	load object "house.3ds",1
	make object sphere 2,2
	color object 2,rgb(255,0,0)

rem settings 2
	color backdrop rgb(0,0,0)

rem path finding variables
	dim coord(9,2)
	dim paths(5,4)

	`bathroom
	paths(1,1) = 985
	paths(1,2) = 9867
	paths(1,3) = 9812
	paths(1,4) = 9834

	coord(9,1) = 15.1
	coord(9,2) = 48.2

	`corridor
	paths(2,1) = 589
	paths(2,2) = 567
	paths(2,3) = 512
	paths(2,4) = 534

	coord(1,1) = 74.7
	coord(1,2) = 29.8

	coord(3,1) = 64.9
	coord(3,2) = 30.3

	coord(5,1) = 51.9
	coord(5,2) = 30.5

	coord(6,1) = 24.9
	coord(6,2) = 31.0

	coord(8,1) = 15.1
	coord(8,2) = 29.3

	`bedroom
	paths(3,1) = 7689
	paths(3,2) = 765
	paths(3,3) = 7612
	paths(3,4) = 7634

	coord(7,1) = 24.9
	coord(7,2) = 10.8

	`sittingroom
	paths(4,1) = 4389
	paths(4,2) = 435
	paths(4,3) = 4312
	paths(4,4) = 4367

	coord(4,1) = 64.9
	coord(4,2) = 48.2

	`kitchen
	paths(5,1) = 2189
	paths(5,2) = 215
	paths(5,3) = 2167
	paths(5,4) = 2134

	coord(2,1) = 74.7
	coord(2,2) = 10.8

	srce_pos = 2
	dest_pos = 0
	path = 0
	arrived = 1

	`initial positions
	position object 2,coord(1,1),4,coord(1,2)
	position camera 50,50,-10
	point camera 50,0,30

rem --------------------------------------------------------------------- rem

do

	rem display directions
	set cursor 25,25:print "1 - goto the bathroom."
	set cursor 25,50:print "2 - goto the bedroom."
	set cursor 25,75:print "3 - goto the kitchen."
	set cursor 25,100:print "4 - goto the sitting room."
	set cursor 25,125:print "5 - goto the corridor."

	rem display room names
	set cursor 200,225:print "- bathroom -"
	set cursor 600,225:print "- sitting room -"
	set cursor 400,350:print "- corridor -"
	set cursor 175,550:print "- bedroom -"
	set cursor 700,550:print "- kitchen -"

	rem changing location
	if arrived = 1
		if keystate(2) = 1 then dest_pos = 9:if srce_pos <> dest_pos:gosub find_path:arrived = 0:endif
		if keystate(3) = 1 then dest_pos = 7:if srce_pos <> dest_pos:gosub find_path:arrived = 0:endif
		if keystate(4) = 1 then dest_pos = 2:if srce_pos <> dest_pos:gosub find_path:arrived = 0:endif
		if keystate(5) = 1 then dest_pos = 4:if srce_pos <> dest_pos:gosub find_path:arrived = 0:endif
		if keystate(6) = 1 then dest_pos = 5:if srce_pos <> dest_pos:gosub find_path:arrived = 0:endif
	endif

	rem control object
	gosub object_ctrl

	sync

loop

rem --------------------------------------------------------------------- rem

	object_ctrl:

		if arrived = 0

			`log object coordinates
			x# = object position x(2)
			z# = object position z(2)

			`obtain house position
			ctr1 = val(mid$(str$(path),ctr2))

			if sqrt((x#-coord(ctr1,1))*(x#-coord(ctr1,1)))+((z#-coord(ctr1,2))*(z#-coord(ctr1,2))) <= 1.5

				`get next house position
				ctr2 = ctr2 + 1
				ctr1 = val(mid$(str$(path),ctr2))

				if ctr1 = 0

					arrived = 1
					srce_pos = dest_pos
					dest_pos = 0
					path = 0

				endif

			endif

			`move object to next house position
			point object 2,coord(ctr1,1),1,coord(ctr1,2)
			move object 2,1

		else

			ctr2 = 2

		endif

	return

rem --------------------------------------------------------------------- rem

	find_path:

		for x = 1 to 5
			for y = 1 to 4

				if len(str$(paths(x,y))) = 3

					`3 point route
					if val(mid$(str$(paths(x,y)),1)) = srce_pos & val(mid$(str$(paths(x,y)),3)) = dest_pos then path = paths(x,y)

				else

					`4 point route
					if val(mid$(str$(paths(x,y)),1)) = srce_pos & val(mid$(str$(paths(x,y)),4)) = dest_pos then path = paths(x,y)

				endif

			next y
		next x

	return

rem --------------------------------------------------------------------- rem

Posted: 10th Mar 2003 3:50
Chronic programmer,

I think your pathfinding could work. But it would be very slow in Real time.

You could use: distance#=sqrt((x2-x1)^2+(y2-y1)^2) formula to determine how far your object is away, but then what...

It's qute hard to use my A* pathfinding, and I have discarted using it now! It just didn't suit my game plan.(Platform Lode Runner) You really have to pick the correct pathfinding for your game.
Posted: 10th Mar 2003 5:33
im sure it will coem in handy eventually
Posted: 10th Mar 2003 6:00
yeah, although they are many different pathfinding techniques you do have to choose the one that suits your game best ^_^ sometimes, for some unique type of games, you may even end up creating your own pathfinding technique from scratch!