perf: less jittery position correction

This commit is contained in:
cha0s 2022-03-15 16:01:07 -05:00
parent 7ddab285f7
commit 8989960697

View File

@ -34,44 +34,6 @@ export default () => class Positioned extends decorate(Trait) {
}; };
} }
static children() {
return {
pointAround: {
type: 'vector',
args: [
{
type: 'number',
},
{
type: 'number',
},
],
},
position: {
type: 'vector',
label: 'Position',
},
setPosition: {
type: 'void',
label: 'Set position to $1.',
args: [
{
label: 'Position',
type: 'vector',
},
],
},
x: {
type: 'number',
label: 'X',
},
y: {
type: 'number',
label: 'Y',
},
};
}
cleanPackets() { cleanPackets() {
super.cleanPackets(); super.cleanPackets();
this.#sidechannelUpdate = false; this.#sidechannelUpdate = false;
@ -145,7 +107,7 @@ export default () => class Positioned extends decorate(Trait) {
}; };
} }
renderTick() { tick(elapsed) {
if (!this.serverPositionDirty) { if (!this.serverPositionDirty) {
return; return;
} }
@ -153,13 +115,11 @@ export default () => class Positioned extends decorate(Trait) {
this.serverPositionDirty = false; this.serverPositionDirty = false;
return; return;
} }
if (Vector.equalsClose(this.trackedPosition, this.serverPosition, 0.1)) { if (Vector.equalsClose(this.trackedPosition, this.serverPosition, 4)) {
this.trackedPosition = this.serverPosition;
this.serverPositionDirty = false;
return; return;
} }
const diff = Vector.sub(this.serverPosition, this.trackedPosition); const diff = Vector.sub(this.serverPosition, this.trackedPosition);
const lerp = 0.5; const lerp = elapsed * 15;
this.trackedPosition = Vector.add(this.trackedPosition, Vector.scale(diff, lerp)); this.trackedPosition = Vector.add(this.trackedPosition, Vector.scale(diff, lerp));
} }