For some simple time-based interpolation I didn't like the way move() worked (It's not time based, it's updated based on when you send the request), and this method had so many issues and was grossly overcomplicated, so I wrote my own.
Anyway, just do your movement as normal on the server and do this at the end of your timeout loop:
PHP Code:
this.attr[1] = "x" @ this.newX;
this.attr[2] = "x" @ this.newY;
this.attr[5] = (this.attr[5] + 1)%200;
I wouldn't suggest writing anything to this.x directly, because if this.x updates, it'll send it to the client and might cause the NPC to jump around on the client. I don't think there's a way around this, at least I haven't thought of it.
In the clientside portion, add this. The lerpBufferSize value dictates how much movement information should be buffered as the server sends it over, and then it's "played back" as if it was a movie. The best way I can relate this is as if you were streaming a video on YouTube and on your **** connection didn't pause it to buffer at the beginning, and instead it has to pause every few seconds while waiting for the server. Similar concept, this smooths it out.
for (i=0;i<this.frames.size()-1;i++) {
f = this.frames[i];
nf = this.frames[i+1];
if (timevar2 >= f.time) {
if (timevar2 <= nf.time) {
if (!this.firstLerp) {
temp.lerp = (timevar2-f.time)/(nf.time-f.time);
function linearInterpolateValue(temp.ov, temp.nv, temp.l) {
return (temp.ov*(1-temp.l)+temp.nv*temp.l);
}
Here's a video demonstrating it real quickly, I toggle it frequently throughout the video. The NPC is just moving around with a .5 timeout on the server using cos/sin, and the interpolation smooths it out to 20 FPS even though the script is running at 2 FPS on the server. Save bandwidth, time, and money! Even if it was running at a .1 timeout on the server, it'd still look really crappy. Interpolation keeps everybody synchronized without looking like garbage.
Thanks! If anybody knows a way to force floating point accuracy into an attr[] without "casting" it as a string, do tell.
Crow
08-21-2011 09:33 PM
Quote:
Originally Posted by Hezzy002
(Post 1664679)
Thanks! If anybody knows a way to force floating point accuracy into an attr[] without "casting" it as a string, do tell.
Never had any problems with this previously. This stuff is pretty awesome, though. I'll use this for sure. Rep++ and a big thanks, sir!
fowlplay4
08-21-2011 10:06 PM
You fool us not Downsider, but nifty script otherwise. I wish the client would do this on it's own though.
DustyPorViva
08-21-2011 10:20 PM
Quote:
Originally Posted by fowlplay4
(Post 1664690)
You fool us not Downsider, but nifty script otherwise. I wish the client would do this on it's own though.
This would be great if the client did it, and way more efficient. You'll be hard-pressed to find even the crappiest online games have interpolation.
Hezzy002
08-21-2011 10:30 PM
Quote:
Originally Posted by DustyPorViva
(Post 1664692)
This would be great if the client did it, and way more efficient. You'll be hard-pressed to find even the crappiest online games have interpolation.
Completely agree. Would be great to be able to toggle and configure a built-in interpolation.