   Movement handling
  Hello,I am looking for a fast way to handle player's movements.I was thinking about these possibilities, can you tell me what the pros/cons they are please ? I am really confused...First, do I have to let the server calculate the client's coordinates and make the server decline every coordinates sent by the client ?How to prevent cheating when I let the client sending it's own coordinates ?Thought solutions, when I press the forward key... :- ...I send a packet to the server as long as my forward key is pressed down. Then the server sends that packet to everyone each milliseconds, then people move me forward on their side until I leave my forward key gets up.- ...I send a packet to the server, which tells everyone that my forward key is down. Then, other players will have to move me forward until I send another packet to tell that my forward key is up.- ...I send my velocity data with my timeElapsed variable, every 10 milliseconds, the other players will just have to calculate the next coordinates I will be.Is it a good way to send a coordinates updates every second to make sure I'm synchronized with other players ?Thanks for your help !   
  I'd have the server determine if the place that your player is walkable the client can do most of everything else...it can send direct cordents so you can update the database.Other then that I don't think the server should really determine anything else..why make it harder on yourself?   ;Quote:Original post by LinaxysFirst, do I have to let the server calculate the client's coordinates and make the server decline every coordinates sent by the client ?How to prevent cheating when I let the client sending it's own coordinates ?Not sure is it even possible to prevent cheating that way. You have to calculate position on server side and validate results are feasible and then you might just as well have server do the calculation.What you could do is maybe have client predict movement with server sending position as often as it can. When client receives position that's new position and client starts to predict from there. Bad side is bit of teleporting around on lag but atleast there would be rough idea.So far my own does it so that I send where I'm heading(forward, rotate left, rotate right, backward etc) which is determined by keyboard presses. I change this only if some key is pressed to prevent flooding. This information is used by server to determine heading and rotation speed which is used to update position which is then sent to all clients(well who are near enough that the information matters. No need for player A to know player B moved if they are so far away they don't interact. Start worrying about them when they CAN interact ;-)Maybe bad idea but smart client seems like cheaters paradise client so this is how I went.   ;  Generally, you let the client run ahead "speculatively," and forward valid movement commands from server to other observing clients as well as back to the moving client. When the moving client detects that displayed position of its "running ahead" avatar is too far out of place, it will snap back to the last valid position from the server. When you run right next to another player in a narrow corridor in CS:S you can feel this sometimes, for example.;  Alright, thank you guys.As my project does not require a very big sync (3D Chat), I've finally decided to make the client sends it's coordinates, the server calculates the distance from the previous coordinates and validates them if it's not too big, and for each player, the server broadcasts the current player's coordinates each second.For smoothing the movements, the client sends each second it's key states QSDW, and sends immediately a packet when he presses on a key, and another one when he releases a key, I don't really like sending a keypress at each loop, I feel it's laggy when I test that on my local machine...I'm sure it's stupid, I don't really trust the lag and networking but...Does it "provoke" a lag to send player's coordinates each seconds ?How many players that method can handle until it makes lag ?Thanks again.[Edited by - Linaxys on April 24, 2009 7:01:07 PM];  Hello,I have a problem while handling rotation updates...The movement is smooth, perfect.But the rotation...When my clone is turning right, his starting yaw angle is set to 90.When it's angle is set to 100, the server sends that it's angle is set to 95, then one second later, it sends 100.Do I have to synchronize the player's timeDelta or the server's one ? (currentTime - lastTime)How can I calculate the angle's distance ? (like "we need 10 units to go from 90 to 100, but how can I do that if the starting angle is 320, and the next angle is 10, since I have set something that we can't go over 360 ?)Here is a little presentation showing how I handle this : SchemaThanks for your help.   ;  Lol, of course, you can go futher than 360. for example, 380 degrees is coterminal to the angle 20 degrees if we are talking in degrees instead of radians.You should first understand basic trogonometry stuff.Man, dont send the whole state information of the object only send his input and timestamp and position only for check for correction.   ;Quote:Original post by becoolnikeyou can go futher than 360. for example, 380 degrees is coterminal to the angle 20 degrees if we are talking in degrees instead of radians.Yes but I think that's really annoying, sometimes I get a huge number like 8745215 degrees, so I've just set a condition that substract 360 if it gets over 360...Thanks for the tip, I'll only send it's input and timestamp.   ;Quote:sometimes I get a huge number like 8745215 degreesThat means you have a bug.;  Arrrrrrrrrrrr !!!Sorry guys but I really don't get it.The client sends his position every 1 second, with his timeElapsed value.timeDelta is (currentTime - lastTime) / 1000.The client calculates it's position locally like this :if (keyState & PacketClass::PK_FORWARD) {pos += movedir * timeDelta * 50.f;} else if (keyState & PacketClass::PK_BACK) {pos -= movedir * timeDelta * 50.f;}if (keyState & PacketClass::PK_RIGHT) {relativeRotation.Y += 25.f * timeDelta;} else if (keyState & PacketClass::PK_LEFT) {relativeRotation.Y -= 25.f * timeDelta;}if (timeToUpdate < Engine->getTime()) {PacketClass velPck(PacketClass::PT_PLAYER_POSITION_UPDATE);velPck.WriteFloat(Cynum->timeDelta);velPck.WriteFloat(pos.X);velPck.WriteFloat(pos.Y);velPck.WriteFloat(pos.Z);velPck.WriteFloat(relativeRotation.Y);Client->sendPacket(&velPck);timeToUpdate = Engine->getTime() + 1000;}Now, the server receives the position, with the client's timeElapsed var, it calculates locally the player's position and sends it back.timeStamp is the timeElapsed sent by the client, inside the newDelta var.f32 newDelta = TPacket->ReadFloat();f32 pX = TPacket->ReadFloat();f32 pY = TPacket->ReadFloat();f32 pZ = TPacket->ReadFloat();f32 rY = TPacket->ReadFloat();timeStamp = newDelta;//// Server loop, calculating player's position, from the keys he is pressing down.//if (keyState & PacketClass::PK_FORWARD) {vector3df rot = node->getRotation();vector3df pos = node->getPosition();pos += rot.rotationToDirection() * 50.f * timeStamp;node->setPosition(pos);} else if (keyState & PacketClass::PK_BACK) {vector3df rot = node->getRotation();vector3df pos = node->getPosition();pos -= rot.rotationToDirection() * 50.f * timeStamp;node->setPosition(pos);}if (keyState & PacketClass::PK_RIGHT) {vector3df rot = node->getRotation();rot.Y += 25.f * timeStamp;node->setRotation(rot);} else if (keyState & PacketClass::PK_LEFT) {vector3df rot = node->getRotation();rot.Y -= 25.f * timeStamp;node->setRotation(rot);}if (positionUpdateTime < Server->getTime()) {// Time to send the new player's position.PacketClass upPck(PacketClass::PT_PLAYER_POSITION_UPDATE);upPck.WriteInt(ID);upPck.WriteFloat(timeStamp);upPck.WriteFloat(node->getPosition().X);upPck.WriteFloat(node->getPosition().Y);upPck.WriteFloat(node->getPosition().Z);upPck.WriteFloat(node->getRotation().Y);Server->broadcastPacket(&upPck);positionUpdateTime = Server->getTime() + 1000;}Then... What happens...As a client, I press on the forward key for about... 100ms,and the server tells that I am at X : 0, Y : 15, Z : 54874.4875221.............But my camera was at X : 0, Y : 15, Z : 8.52000.......Can anyone tell me what I am doing wrong please ?Thanks.   