Game Development Community

Is there a moveTo function for static objects?

by Andy Hawkins · in Torque Game Engine Advanced · 06/10/2007 (7:49 am) · 2 replies

I know static object are supposed to be stationary, but as they use less overhead with the server I wanted to try and use them as the basis of my aliens.

Does anyone know if there is a moveTo command or something similar for static objects. I'm having a bit of trouble with the math. Or is there a better way to load my alien space ship and have it follow points, move to objects etc?

Here's what I've written so far...

function AIPlayer::create(%dataBlock,%position,%rotation,%scale)
{
   // Load object
   %obj = new TSStatic() {
      shapeName = %dataBlock;
      static = true;
      position = %position;
      scale = %scale;
      rotation = %rotation;
      rotate = true;
   };
   return %obj;
}

function AIPlayer::getDistance(%x1,%y1,%z1,%%x2,%y2,%z2)
{
   return mSqrt(((%x2 - x1)^ 2) + ((%y2 - y1)^ 2) + ((%z2 - z1)^ 2);
   
}
function AIPlayer::moveTo(%obj, %position)
{
   %arrived = false;
   
   %Xpos = getWord(%position, 0);
   %Ypos = getWord(%position, 1);
   %Zpos = getWord(%position, 2);
   
   // compare position
   %OPosition = %obj.getPosition();
   %OPosX = getWord(%OPosition, 0);
   %OPosY = getWord(%OPosition, 1);
   %OPosZ = getWord(%OPosition, 2);
   
   // get range
   range = getDistance(%Xpos,%Ypos,%Zpos,%OPosX,%OPosY,%OPosZ);
   
   if (range < 2 )
   {
      // 1. draw a vector to position
      // 2. divide distance by current move speed
      // 3. displace object to new vector
      
   }
   else
       %arrived = true;
   
   return %arrived;
}

#1
06/10/2007 (3:37 pm)
First thing I've noticed: you wrote your own getDistance function when you could be using the built-in VectorDist function.

Secondly, I would really really recommend you not use a TSStatic implementation. You will be fighting the engine uphill every inch of the way if you are trying to use that object for anything that requires functionality. You're going to need to write your own code for animation, damage effects... everything.

You'll probably just end up building TSStatic up to a point where it has most of the same functionality as the Player class. If you're worried about server load, then create a new object inherited from ShapeBase with only what you need. From there you can work your way up the inheritance tree and remove what you don't need from other objects. Trust me, this will save you a lot of work.
#2
06/10/2007 (4:28 pm)
The alien is an unanimated object and more closely related to a flying vehicle, than a player class. What is most appropriate class for alien spaceships, with built in move functions in mind then? What have other people done in their games when incorporating aliens as vehicles?

Should I be looking toward the AIFlyingVehicle based threads?