From 3a17a64c991108a04d1dfc1d817d3db028cbabc1 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 24 Jan 2017 11:56:50 -0800 Subject: [PATCH 1/4] V1 of these filters --- .../entity-server-filter-example.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/script-archive/entity-server-filter-example.js b/script-archive/entity-server-filter-example.js index 2ccb550acd..ce35964a79 100644 --- a/script-archive/entity-server-filter-example.js +++ b/script-archive/entity-server-filter-example.js @@ -9,6 +9,25 @@ function filter(p) { /* Can also reject altogether */ if (p.userData) { return false; } + + /* Reject if modifications made to Model properties */ + if (p.modelURL || p.compoundShapeURL || p.shape || p.shapeType || p.url || p.fps || p.currentFrame || p.running || p.loop || p.firstFrame || p.lastFrame || p.hold || p.textures || p.xTextureURL || p.yTextureURL || p.zTextureURL) { return false; } + + /* Clamp velocity to 10 units/second. Zeroing each component of acceleration keeps us from slamming.*/ + if (p.velocity) { + if (p.velocity.x > 10) { + p.velocity.x = 10; + p.acceleration.x = 0; + } + if (p.velocity.y > 10) { + p.velocity.y = 10; + p.acceleration.y = 0; + } + if (p.velocity.z > 10) { + p.velocity.z = 10; + p.acceleration.z = 0; + } + } /* If we make it this far, return the (possibly modified) properties. */ return p; From 0e16686fb8ab0b5dab36e02c8b0749dacaa0236f Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 24 Jan 2017 12:11:33 -0800 Subject: [PATCH 2/4] Change the velocity filter to 5 --- script-archive/entity-server-filter-example.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/script-archive/entity-server-filter-example.js b/script-archive/entity-server-filter-example.js index ce35964a79..e3a0426087 100644 --- a/script-archive/entity-server-filter-example.js +++ b/script-archive/entity-server-filter-example.js @@ -13,18 +13,18 @@ function filter(p) { /* Reject if modifications made to Model properties */ if (p.modelURL || p.compoundShapeURL || p.shape || p.shapeType || p.url || p.fps || p.currentFrame || p.running || p.loop || p.firstFrame || p.lastFrame || p.hold || p.textures || p.xTextureURL || p.yTextureURL || p.zTextureURL) { return false; } - /* Clamp velocity to 10 units/second. Zeroing each component of acceleration keeps us from slamming.*/ + /* Clamp velocity to 5 units/second. Zeroing each component of acceleration keeps us from slamming.*/ if (p.velocity) { - if (p.velocity.x > 10) { - p.velocity.x = 10; + if (p.velocity.x > 5) { + p.velocity.x = 5; p.acceleration.x = 0; } - if (p.velocity.y > 10) { - p.velocity.y = 10; + if (p.velocity.y > 5) { + p.velocity.y = 5; p.acceleration.y = 0; } - if (p.velocity.z > 10) { - p.velocity.z = 10; + if (p.velocity.z > 5) { + p.velocity.z = 5; p.acceleration.z = 0; } } From 53173d8f037a71cf33898ede0b25869263b3045b Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 24 Jan 2017 12:50:18 -0800 Subject: [PATCH 3/4] use var for maxvelocity --- script-archive/entity-server-filter-example.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/script-archive/entity-server-filter-example.js b/script-archive/entity-server-filter-example.js index e3a0426087..4b3a8a7212 100644 --- a/script-archive/entity-server-filter-example.js +++ b/script-archive/entity-server-filter-example.js @@ -13,18 +13,19 @@ function filter(p) { /* Reject if modifications made to Model properties */ if (p.modelURL || p.compoundShapeURL || p.shape || p.shapeType || p.url || p.fps || p.currentFrame || p.running || p.loop || p.firstFrame || p.lastFrame || p.hold || p.textures || p.xTextureURL || p.yTextureURL || p.zTextureURL) { return false; } - /* Clamp velocity to 5 units/second. Zeroing each component of acceleration keeps us from slamming.*/ + /* Clamp velocity to maxVelocity units/second. Zeroing each component of acceleration keeps us from slamming.*/ + var maxVelocity = 5; if (p.velocity) { - if (p.velocity.x > 5) { - p.velocity.x = 5; + if (p.velocity.x > maxVelocity) { + p.velocity.x = maxVelocity; p.acceleration.x = 0; } - if (p.velocity.y > 5) { - p.velocity.y = 5; + if (p.velocity.y > maxVelocity) { + p.velocity.y = maxVelocity; p.acceleration.y = 0; } - if (p.velocity.z > 5) { - p.velocity.z = 5; + if (p.velocity.z > maxVelocity) { + p.velocity.z = maxVelocity; p.acceleration.z = 0; } } From 9796a476eacabd4775de99796acd327335811ef0 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Tue, 24 Jan 2017 15:08:17 -0800 Subject: [PATCH 4/4] Clamp negative velocity too --- script-archive/entity-server-filter-example.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/script-archive/entity-server-filter-example.js b/script-archive/entity-server-filter-example.js index 4b3a8a7212..ab4d813927 100644 --- a/script-archive/entity-server-filter-example.js +++ b/script-archive/entity-server-filter-example.js @@ -16,16 +16,16 @@ function filter(p) { /* Clamp velocity to maxVelocity units/second. Zeroing each component of acceleration keeps us from slamming.*/ var maxVelocity = 5; if (p.velocity) { - if (p.velocity.x > maxVelocity) { - p.velocity.x = maxVelocity; + if (Math.abs(p.velocity.x) > maxVelocity) { + p.velocity.x = Math.sign(p.velocity.x) * maxVelocity; p.acceleration.x = 0; } - if (p.velocity.y > maxVelocity) { - p.velocity.y = maxVelocity; + if (Math.abs(p.velocity.y) > maxVelocity) { + p.velocity.y = Math.sign(p.velocity.y) * maxVelocity; p.acceleration.y = 0; } - if (p.velocity.z > maxVelocity) { - p.velocity.z = maxVelocity; + if (Math.abs(p.velocity.z) > maxVelocity) { + p.velocity.z = Math.sign(p.velocity.z) * maxVelocity; p.acceleration.z = 0; } }