Game Development Community

How can I get the postion of a object in the engine?

by Martin Edmaier · in Torque Game Engine · 03/05/2002 (10:12 am) · 1 replies

I need the position of an object for a bot..
Please help me can anybody script that..

Thankx,

Martin

#1
03/05/2002 (10:34 am)
Code or script?

Code wise:

Sim::findObject("Name"); or Sim::findObject(ObjectId);
in a dynamic cast which would cast it to that type. I'm not sure what an AIObject type is for the engine..but as an example I'll use the terrain:

TerrainBlock *terr = dynamic_cast(Sim::findObject("Terrain"));

You would then use terr->getPosition(); and it will return a Point3F of where the object is in the game world. Of course you'll want to adapt this example to the type of object you need to get, which I'm not sure about AI objects.


Script wise:
You just do %obj.getTransform();
I believe this returns a set of 7 numbers seperated by a space. For the camera you will only be interested in the first 3 numbers, the x y z location.
To get these first three numbers do something like:

%params = %obj.getTransform();
%valX = getWord( %params, 0 );
%valY = getWord( %params, 1 );
%valZ = getWord( %params, 2 );

And thats all you should need.