Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 20 Aug 2013
Offline Last Active Dec 16 2013 03:23 AM

Topics I've Started

Problem with client side prediction

14 December 2013 - 04:25 PM



client side prediction is not working as intended :(

the other players char is still not walking fluently.


heres the code:

every 10 seconds, thread 1

//gets position of players from server
//user.isUpToDate is being set to true by server
 WorldPlayers = (Data.CharacterObjects.CPlayerInstance[])NetworkComms.SendReceiveObject<Data.CharacterObjects.CPlayerInstance[]>("RequestUWP", "", 999, "UWPReply", 5000, "");


at every frame, called from main loop:^
user is the player character from WorldPlayers
(CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).newPosition is the current ppsition in the data structure
((CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).m_Node.Position is the physical position of the entity

		if (!user.isUpToDate)
		    //extrapolate new position if position is not up to date
                    ((CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).newPosition = ((CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).m_Node.Position(((CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).m_Node.Position - ((CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).oldPosition);
                    user.isUpToDate = true;

                    IrrlichtLime.Core.Vector3Df v = new IrrlichtLime.Core.Vector3Df();
                    //interpolate between current position and new position
                    v = v.Interpolate(((CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).m_Node.Position, ((CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).newPosition, getTime() - ((CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).lastUpdate);
                    ((CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).m_Node.Position = v;
                    ((CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).lastUpdate = getTime()
		    //if current position==new positin, start extrapolation
                    if (v == ((CCharacter)CScene.Characters.m_CCharacterWorldPlayers[user.ID]).newPosition)
                        user.isUpToDate = false;