32
« on: September 06, 2008, 05:12:04 pm »
I'm a totally stuck on the maths trying to sync the movement on the server with the client. Before this I had it so the client sync with the server but that caused annoying warp backs, so I'm trying to make it so the server syncs to the client.
Hopefully I'm too confusing trying to explain this.
The server holds the current client position(CC), current server position (CS), old client position(OC).
The server on every cycle sync as much as it can to the client.
This is done by creating a guess position(G) which the CS goes towards that direction to N (The new position).
G is worked out by the angle of OC and CC, then translate CC with this new angle.
N is worked out by the angle of CS and G, then translate CS with this new angle.
This is my current code but doesn't work as expected, just moves in one direction. Hopefully someone understands this and able to tell me whats wrong.
float differenceAngle = oldrotation - rotation; //has the player turned since last cycle.
final Object3D guessPos = new Object3D(0), charObj = new Object3D(0), newPos = new Object3D(0);
guessPos.translate(clientX, y, clientZ);
guessPos.rotateY(calcAngle(new SimpleVector(oldClientX,y,oldClientZ),new SimpleVector(clientX,y,clientZ)) + differenceAngle);
charObj.translate(x, y, z);
charObj.rotateY(rotation);
final SimpleVector charPos = charObj.getTranslation();
SimpleVector a = guessPos.getZAxis();
a.scalarMul(xSpeed);
newPos.translate(x, y, z);
newPos.rotateY(calcAngle(new SimpleVector(charPos.x,charPos.y,charPos.z),new SimpleVector(a.x,a.y,a.z)));
clientX = a.x;
clientZ = a.y;
clientRotation = a.z;
a = newPos.getZAxis();
a.scalarMul(xSpeed);
a = m.getWorld().checkCollisionEllipsoid(charPos, a, Zone.ELLIPSOID_RADIUS, 2);
charObj.translate(a);
a = charObj.getTranslation();
x = a.x;
y = a.y;
z = a.z;
oldClientX = clientX;
oldClientZ = clientZ;
oldClientRotation = clientRotation;
oldrotation = rotation;