perf: less jittery position correction
This commit is contained in:
parent
7ddab285f7
commit
8989960697
|
@ -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() {
|
||||
super.cleanPackets();
|
||||
this.#sidechannelUpdate = false;
|
||||
|
@ -145,7 +107,7 @@ export default () => class Positioned extends decorate(Trait) {
|
|||
};
|
||||
}
|
||||
|
||||
renderTick() {
|
||||
tick(elapsed) {
|
||||
if (!this.serverPositionDirty) {
|
||||
return;
|
||||
}
|
||||
|
@ -153,13 +115,11 @@ export default () => class Positioned extends decorate(Trait) {
|
|||
this.serverPositionDirty = false;
|
||||
return;
|
||||
}
|
||||
if (Vector.equalsClose(this.trackedPosition, this.serverPosition, 0.1)) {
|
||||
this.trackedPosition = this.serverPosition;
|
||||
this.serverPositionDirty = false;
|
||||
if (Vector.equalsClose(this.trackedPosition, this.serverPosition, 4)) {
|
||||
return;
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user