Game Development Community

AIPlayer.cpp Checking Closest Path node

by BryceSquared · in Torque 3D Professional · 10/08/2009 (11:11 am) · 2 replies

I wrote this up today, and it compiled... "YES I MUST BE LEARNING!"

void AIPlayer::findNodeDistance( Point3F &node, Point3F &result )
{
	 result = node - mAIpos;
}

ConsoleMethod( AIPlayer, findNodeDistance, void, 3, 4, "( Point3F &node, Point3F &result )"
			  "Stores the distance from the AI to the node.")
{
	Point3F x( 0.0f, 0.0f, 0.0f );
	dSscanf( argv[2], "%g %g %g", &x.x, &x.y, &x.z );
	Point3F y = x;
	object->findNodeDistance( x, y );
}

I tried the console command and it worked, things were looking good...

Tried echoing the variable and i just got a black line echoed back.

Any suggestions? I think it might be the way I tried to get the AI's position.

mAIpos = Point3F(0.0f, 0.0f, 0.0f );

Now that is probably wrong as my knowledge of variables in the engine is abysmal.

What this will hopefully one day do is look through an entire Path in the MissionGroup and store the closest waypoint to the player that is in Line of Sight and is not the one last moved to. So i should be able to get some basic pathfinding that is good enough for my game :)

I appreciate any help with anything I just explained (sorry if my wording is bad it's 1:11 here and I'm buggered :o)

#1
10/08/2009 (2:25 pm)
No,it is not wrong.
mAIpos = Point3F(0.0f, 0.0f, 0.0f );
is good.

you can use also:
mAIpos.set(0,0,0);
#2
10/08/2009 (2:37 pm)
TorqueScript doesn't support passing-by-reference, therefore your function does nothing. Try this one instead:

void AIPlayer::findNodeDistance( Point3F &node, Point3F &result )
{
	 result = node - mAIpos;
}

ConsoleMethod( AIPlayer, findNodeDistance, const char*, 3, 3, "( Point3F node )"
			  "Returns the distance from the AI to the node.")
{   
	Point3F x( 0.0f, 0.0f, 0.0f );
	dSscanf( argv[2], "%g %g %g", &x.x, &x.y, &x.z );
	Point3F y = x;
	object->findNodeDistance( x, y );

   char *retBuffer = Con::getReturnBuffer(64);
   dSprintf(retBuffer, 64, "%g %g %g", y.x, y.y, y.z);
   return retBuffer;
}

My suggestion when creating console methods and functions: always search the source code for one that most closely resembles the one you want to create (same return value and similar arguments), copy it and modify it to your liking. It's the fastest and safest way.