Game Development Community

Problems with AStar resource

by Andre Lind · in Torque Game Builder · 03/23/2007 (4:11 am) · 6 replies

Hi!
I'm trying to get the Astar resource (http://tdn.garagegames.com/wiki/TGB/Source/Pathfinding) working with my game but I'm having some problems...
The character moves as he should but totally ignores any objects

Heres a screen:
www.frikkinsoft.eu/NeoFantasy/AStar.png
As you can see, the tree is totally ignored
This is my code for "starting up" the movement:
function t2dSceneWindow::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
       %x = mfloor(getWord(%worldPosition,0));
	%y = mfloor(getWord(%worldPosition,1));
	
	moveToAstar($controlledChar, 
		findPath($controlledChar, 
		%x SPC %y, 
		mfloor($controlledChar.getWidth() /2), 
		100),
		$controlledChar.runSpeed);
}

Anyone have any idea on why the tree is ignored? I've tried to change the maximum number of nodes from 100 to 1000 to, but with the same result...

#1
03/23/2007 (8:14 am)
Ok, I had completely missed the "cost" field...
But some problems still remain :(

How can i make my character "go wider" from the objects?
RIght now it's walking beside by just a little and sometimes colliding with the object making the character walk in random straight direction....

My character has cost = 1 and my trees cost = 100

Any suggestions on how to fix this?
#2
06/02/2007 (12:17 pm)
Andre,

I was researching A* before I got TGB and hoping to incorporate it into my games, so when I saw somebody posted a resource that should make A* easy, I was very happy. However, after taking a quick look at it just now, it seems to me that it is much more complex than it should be. Maybe that's just my inexperience with TorqueScript and/or A* programming talking, but really, it seems like a ton of code for something that shouldn't be that hard to do.

Maybe you should do a little A* research yourself and see if it helps you resolve the problems you're having or maybe it will help you implement your own version of it into your code. I'll post some links to various A* resources I've read and found very helpful. I recommend you read them all:

A* Pathfinding for Beginners - Really helpful to get your head wrapped around the theory of A*. I suggest you read this first if you're not really sure what A* is or how it works. He also goes into a little more depth with Two-Tiered pathfinding which helps save your CPU when you've got things that need to travel long distances.
Amit's A* Pages - I'm not sure who Amit is, but he understands A* very well and goes into real depth of pathfinding. This might be confusing if you don't read the beginners tutorial first and it might still be confusing even if you have read it. Very useful reference material here.

Also you can check out Wikipedia's A* page. It has some good general information with links to more resources.

If you want to see a quick and dirty A* example in motion, with the ability to "paint" some different terrain with different costs, check out this Flash A* example. You can even download the source if you want. It doesn't move the thing across the map, but it shows you exactly how it searches for the path, step by step.

I hope this helps you out.
#3
06/02/2007 (12:26 pm)
And I just found this one, which might be exactly what you're looking for:

More Realistic Pathfinding - Article on Gamasutra, which requires a free registration (or BugMeNot) to view.
#4
06/02/2007 (1:28 pm)
For all interested, there's actually a C++ version of A* available for TGB. Of course, it requires that you have the Pro version since you need to recompile TGB. Here's the link.

It's work great for me though a few people have had some issues. Check out the comments on the resource for details.
#5
05/05/2008 (9:49 pm)
As the original author of the badly implemented A* mentioned.. I can give you a few hints as to why it might not be working quite correctly.

First of all it makes some really , really bad assumptions. It was meant to be more of a "you can do this" this TS...
But you really shouldn't. Its expensive for the cpu and your game wont perform well. This should be done in the core engine as mentioned in c++. The resource Dennis mentions is a really really good start at one.

This was also written for TGB 1.1 or T2D as it was known then, nd I haven't played with it since.

The only thing I can think of is perhaps turning on the debugs and verifying if your object costs are dumping to the console as they should be.. the code just uses a pickRect to find objects , look at their "cost" values, and is supposed to take them into account to help it "pick" a suitable path. Check the getObjectCost() function.

I'll be happy to take a further look at it for you, if you send to me "rrindels" at "gmail.com".
#6
05/20/2008 (7:36 pm)
A* is now in stock TGB 1.7.3!