Game Development Community

Updating position from alternative source

by Gaelen Hadlett · in Torque Game Engine · 10/14/2005 (11:33 am) · 3 replies

I am implementing a vehicle that that receives position and rotation coordinates from a secondary object. I am using a modified vehicle class (Vehicle3d) to support rolling and a clone of hovervehicle class (HeloVehicle) that makes calls to the secondary object (mPhysicsModel) in a similar way as it references mDatablock. mPhysicsModel takes in proper joystick controls and outputs a position and rotationvector. I use the output vectors to position and orient my vehicle.

I am experiencing two problems: adding the vehicle sets it to position (0,0,0) instead of where it normally should be set to; and the vehicle jitters back and forth.

Below is the portion of code I added to the very beginning of HeloVehicle::onAdd() prior to the call to Parent::onAdd().
if( !mPhysicsModel->is_initialized() ) {
   mHeloPhysics->sh_initialize(mRigid.linPosition.x, mRigid.linPosition.y, mRigid.linPosition.z);
}

Below is the relevant parts I have added to HeloVehicle::processTick(move). Basicly it is a copy of Vehicle::processTick() with a call to Parent::Parent::processTick().
Parent::Parent::processTick(move);

//...unchanged pieces of Parent(Vehicle)::processTick()...

   //starting at updateMove(move) in the root level else statement
   updateMove(move);
   mPhysicsModel->update(move->z, move->pitch, move->roll, move->yaw,
                         &posx, &posy, &posz, &roty, &rotp, &rotr);
   QuatF rotq.set(EulerF(-rotp*DEG2RAD, -rotr*DEG2RAD, -roty*DEG2RAD));
   mRigid.linPosition.set(posx, posy, posz);
   mRigid.angPosition.set(rotq.x, rotq.y, rotq.z, rotq.w);

   //rest of code is same as Vehicle::processTick() starting at 
   // Save current rigid state interpolation
   mDelta.posVec = mRigid.linPosition;
   mDelta.rot[0] = mRigid.angPosition;
   ...

Also, I do not call updateForces() in updatePos().

I don't know why onAdd is being called twice, but that's probably why my problems occur. With the above portion squashed between updateMove() and setting current rigid state, the vehicle is placed to {0,0,0} and then a tiny offset of {0,0,0}. In the unmodified HoverVehicle, onAdd is called twice, once to {0,0,0} and again a few ticks later to the currect position. It appears that my updating of mRigid.linPosition between the first call and the second call to onAdd is throwing it off.

For testing, I hardcoded onAdd to a specific location. All the rotations work fine, but position jumps around. The jumps start small and get wider. Can anyone give me pointers on how to fix either of these problems? I haven't been able to find very good documentation on mRigid or mDelta.

#1
10/14/2005 (11:51 am)
You are almost certainly running into an issue with client side interpolation not being coordinated with your server side physics, and/or a conflict between the original Torque vehicle physics and your physics updates.

FYI, onAdd is most likely being called once for the server side object, and once for the client side object, so the output is misleading...it's actually not being called twice for one object, but once for each object in each simulation (client sim and server sim).
#2
10/14/2005 (1:51 pm)
So I would only want to call my mPhysicsModel->update() when the isServerObject() is true, otherwise interpolate using mDelta.warp?
#3
10/14/2005 (2:11 pm)
Off the cuff that sounds correct.

Also keep in mind that interpolateTick() is only called client side, and is used to "recover" from an out of synch position, where the client say "I'm here", and the server says "no, you are there!". The client then interpolates rapidly over the difference in positions, ending up at the server's authoritative location. This may be part of the issue--either the interpolation isn't accurate, or is thrashing back and forth somehow.