mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-31 08:41:41 +02:00
added script to generate a lot of physical blocks within a specified range
This commit is contained in:
parent
cac5fa1371
commit
3ee111d757
1 changed files with 63 additions and 0 deletions
63
examples/lotsoBlocks.js
Normal file
63
examples/lotsoBlocks.js
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
var NUM_BLOCKS = 200;
|
||||||
|
var size;
|
||||||
|
var SPAWN_RANGE = 10;
|
||||||
|
var boxes = [];
|
||||||
|
var basePosition, avatarRot;
|
||||||
|
var isAssignmentScript = false;
|
||||||
|
if(isAssignmentScript){
|
||||||
|
basePosition = {x: 8000, y: 8000, z: 8000};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0);
|
||||||
|
basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(SPAWN_RANGE * 3, Quat.getFront(avatarRot)));
|
||||||
|
}
|
||||||
|
basePosition.y -= SPAWN_RANGE;
|
||||||
|
|
||||||
|
var ground = Entities.addEntity({
|
||||||
|
type: "Model",
|
||||||
|
modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/woodFloor.fbx",
|
||||||
|
dimensions: {
|
||||||
|
x: 100,
|
||||||
|
y: 2,
|
||||||
|
z: 100
|
||||||
|
},
|
||||||
|
position: basePosition,
|
||||||
|
shapeType: 'box'
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
basePosition.y += SPAWN_RANGE + 2;
|
||||||
|
for (var i = 0; i < NUM_BLOCKS; i++) {
|
||||||
|
size = randFloat(-.2, 0.7);
|
||||||
|
boxes.push(Entities.addEntity({
|
||||||
|
type: 'Box',
|
||||||
|
dimensions: {
|
||||||
|
x: size,
|
||||||
|
y: size,
|
||||||
|
z: size
|
||||||
|
},
|
||||||
|
position: {
|
||||||
|
x: basePosition.x + randFloat(-SPAWN_RANGE, SPAWN_RANGE),
|
||||||
|
y: basePosition.y - randFloat(-SPAWN_RANGE, SPAWN_RANGE),
|
||||||
|
z: basePosition.z + randFloat(-SPAWN_RANGE, SPAWN_RANGE)
|
||||||
|
},
|
||||||
|
color: {red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255},
|
||||||
|
collisionsWillMove: true,
|
||||||
|
gravity: {x: 0, y: 0, z: 0}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
|
Entities.deleteEntity(ground);
|
||||||
|
boxes.forEach(function(box){
|
||||||
|
Entities.deleteEntity(box);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(cleanup);
|
||||||
|
|
||||||
|
function randFloat(low, high) {
|
||||||
|
return low + Math.random() * ( high - low );
|
||||||
|
}
|
Loading…
Reference in a new issue