Game Development Community

Ambiguous 3D Motion

by Kirk Haynes · in Torque Game Engine · 09/08/2006 (1:21 pm) · 1 replies

I'm trying to implement generic reference motion into a 3D object, that doesn't require constant position updates from the server to the client, but it doesn't seem to be synchronizing properly between server and client, and I don't know why. When I step through the code the values all work out correctly but the positon on the client isn't what it's supposed to be at the end, after some kind of hickup.

I inititilize the motion on the server object.

void MotionItem::NewMotion( VectorF & motion, S32 ticks)
{
    mMotion = true;
    mMotionVector = motion;
    mMotionTicks = ticks;                      // used to send the value unaltered to the client
    mMotionTicksRemaining = ticks;      // used by processTick

    setMaskBits( MotionMask);
}


U32 MotionItem::packUpdate( NetConnection * connection, U32 mask, BitStream * stream)
{
    U32 retMask = Parent::packUpdate( connection, mask, stream);

    if ( stream->writeFlag( mask & MotionMask) )
    {
        mathWrite( *stream, mMotionVector);
        stream->writeInt( mMotionTicks, 9);
    }

    return retMask;
}


void MotionItem::unpackUpdate(NetConnection *connection, BitStream *stream)
{
    Parent::unpackUpdate( connection, stream);

    if ( stream->readFlag() )		// MotionMask
    {
        mMotion = true;
        mathRead( *stream, & mMotionVector);
        mMotionTicksRemaining = stream->readInt( 9);
    }
}

void MotionItem::processTick( const Move * move)
{
    Point3F position;
    MatrixF transform = mObjToWorl;

    position = transform.getPosition();

    if ( mMotion )
    {
        position += mMotionVector;
        --mMotionTicksRemaining;
        if ( mMotionTicksRemaining <= 0 )
        {
            mMotion = false;
        }

        transform.setPosition( position);
  
        Parent::setTransform( transform);
    }
}

It was suggested that I may need to integrate this with interpolateTick and warpticks to make it come out correctly. How do I do that?

#1
09/08/2006 (4:44 pm)
Turns out this code works fine. In the actual implementation the PostionMask was sent after this motion completed on the server. The client was receiving it before it had a chance to finish movement to what the server was setting as the final position with the PositionMask. Removing the setMaskBits( PositionMask) from my implementation allows this code to work.