Game Development Community

Moving Static Objects Smoothly

by Cinder Games · in Torque Game Engine · 09/20/2005 (4:46 pm) · 1 replies

I did a little searching on this topic, didn't seem to find the right keywords...

Let me simply state what i am trying to do. I'm trying to use a DTS object, with no mesh, as sorta a "target" for my camera system. I'm using the advance camera resource, with object tracking. I want to pretty much call a move function like the ai setdestination, for my static DTS. I need the moving to not be affected by gravity and collsision. Simply tell it move here at this speed.

while i've created a function that does just what i need in torque script, no matter how quickly i set it's position with settransform, it jitters, not smooth movement.

Anyone have some ideas on where to go? i was thinking i could use the hover vechicle class, and find some way to disable collision.. but i'd prefer a much simpler method.

#1
09/20/2005 (8:06 pm)
Look into how Paths work. I'm fairly confident this is what you need. Basically, you can set waypoints of a path and each "leg" of the path has a "time" that states how long it should take to travel along that leg. There are helper functions that will return the coordinates of the path given a time. It's actually quite handy.

Make a new class and derive it from... well, I derived it from AIVehicle, but you could probably just derive it from Vehicle.

Other than the basics, here's the main block of code that's needed:

void AITram::updateForces(F32 dt)
{
   mRigid.clearForces();

   PathManager* pPathManager;

   // Get the appropriate path manager
   if (isServerObject())
   {
      pPathManager = gServerPathManager;
   }
   else
   {
      pPathManager = gClientPathManager;
   }

   Point3F position;
   QuatF rotation;

   Path* pPath = dynamic_cast<Path*>(Sim::findObject(mDataBlock->mPathName));
   if (pPath)
   {
      mCurrentTime += dt * 1000;

      U32 pathIndex = pPath->getPathIndex();
      U32 pathTime = pPathManager->getPathTotalTime(pathIndex);

      if (pPath->isLooping())
      {
         // Update mCurrentTime with the corrected value for looping
         while(pathTime < mCurrentTime)
         {
            mCurrentTime -= pathTime;
         }
      }
      else
      {
         if (pathTime < mCurrentTime)
         {
            mCurrentTime = 0;
            throwCallback("onEndOfPath");
            mDataBlock->mPathName = StringTable->insert("");
            return;
         }
      }

      pPathManager->getPathPosition(pathIndex, mCurrentTime, position, rotation);
      // setPosition(position, rotation);

      MatrixF xRot, zRot;
      xRot.set(EulerF(rotation.x, 0, 0));
      zRot.set(EulerF(0, 0, rotation.z));
      MatrixF temp;
      temp.mul(zRot, xRot);
      temp.setColumn(3, position);

      mRigid.setTransform(temp);
   }
}

Hope that helps.