Client Side Prediction for a Look Vector

Posted by Mike Sawayda on Game Development See other posts from Game Development or by Mike Sawayda
Published on 2012-10-24T03:45:23Z Indexed on 2012/10/24 5:28 UTC
Read the original article Hit count: 229

So I am making a first person networked shooter. I am working on client-side prediction where I am predicting player position and look vectors client-side based on input messages received from the server. Right now I am only worried about the look vectors though. I am receiving the correct look vector from the server about 20 times per second and I am checking that against the look vector that I have client side. I want to interpolate the clients look vector towards the correct one that is server side over a period of time. Therefore no matter how far you are away from the servers look vector you will interpolate to it over the same amount of time. Ex. if you were 10 degrees off it would take the same amount of time as if you were 2 degrees off to be correctly lined up with the server copy. My code looks something like this but the problem is that the amount that you are changing the clients copy gets infinitesimally small so you will actually never reach the servers copy. This is because I am always calculating the difference and only moving by a percentage of that every frame. Does anyone have any suggestions on how to interpolate towards the servers copy correctly?

if(rotationDiffY > ClientSideAttributes::minRotation)
{

    if(serverRotY > clientRotY)
    {
        playerObjects[i]->collisionObject->rotation.y += (rotationDiffY * deltaTime);
    }
    else
    {
        playerObjects[i]->collisionObject->rotation.y -= (rotationDiffY deltaTime);
    }

}

© Game Development or respective owner

Related posts about physics

Related posts about server