Hi there, I have some few questions about handle the players for an ( rpg game that I have been working on ). The problem I have here is to get the camera follow the exakt player. This is how my idea looks like how I handle the players. The server got an (online players) vector of the players data structure to hold all the current online players on the map. vector<WPlayerData> sOnlinePlayers; Now to the client part. Client got the same structure as server using an vector to hold the players. vector<WPlayerData> cOnlinePlayers; 1. When a new player connect he recv an Unique ID and all the players he got in the databas, and from there chose wich one he wants to play with and press "Enter World". 2. The client sends an packet to the server to recv the sOnlinePlayers vector, to get all the current online players on the map. 3. The client send an packet to server to add him into the sOnlinePlayer vector. and also send out to all the clients connected "new player enter world. Add me to the client cOnlinePlayers vector". 4. Render/Update the players in cOnlinePlayers vector. The problem I have is that I can't get the camera to follow the right character and it looks like this.
Vector3 camPos; //camPos
camPos = cOnlinePlayers[ my_unique_id ].m_Position; //playerPos
m_Camera.SetCamera( camPos ); //Setcamera
But this suxs. if an player leave the game he gets removed from the cOnlinePlayer vector, And then my character does not have the same ID pos in the cOnlinePlayers vector as before right?. So how can I fix this?. My idea was to do something like this.
int pID;
for( itr = cOnlinePlayers.begin(); itr != cOnlinePlayers.end(); itr++ )
{
if( itr->GetID() == my_unique_id ) { pID = itr->GetID(); }
}
and from there use the pID as the position id in the vector. camPos = cOnlinePlayers[ pID ].m_Position; //playerPos m_Camera.SetCamera( camPos ); //SetCamera ------------- Well I hope anyone can indicate what I have been writing here because I am not good at explain and my english is not the best to.. Anyway, I hope you guys can point me somewere.