content/hifi-content/zfox/sandbox-filter.js
2022-02-14 02:04:11 +01:00

33 lines
1.4 KiB
JavaScript

function filter(p) {
/* Define an axis-aligned zone in which entities are not allowed to enter. */
/* This example zone corresponds to an area to the right of the spawnpoint
in your Sandbox. It's an area near the big rock to the right. If an entity
enters the zone, it'll move behind the rock.*/
if (p.position) {
/* Random near-zero value used as "zero" to prevent two sequential updates from being
exactly the same (which would cause them to be ignored) */
var nearZero = 0.0001 * Math.random() + 0.001;
/* Define the points that create the "NO ENTITIES ALLOWED" box */
var boxMin = {x: 25.5, y: -0.48, z: -9.9};
var boxMax = {x: 31.1, y: 4, z: -3.79};
/* Define the point that you want entites that enter the box to appear */
var resetPoint = {x: 29.5, y: 0.37 + nearZero, z: -2};
var x = p.position.x;
var y = p.position.y;
var z = p.position.z;
if ((x > boxMin.x && x < boxMax.x) &&
(y > boxMin.y && y < boxMax.y) &&
(z > boxMin.z && z < boxMax.z)) {
p.position = resetPoint;
if (p.velocity) {
p.velocity = {x: 0, y: nearZero, z: 0};
}
if (p.acceleration) {
p.acceleration = {x: 0, y: nearZero, z: 0};
}
}
}
return p;
}