forked from yozlet/interface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlotsoBlocks.js
63 lines (55 loc) · 1.46 KB
/
lotsoBlocks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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},
dynamic: 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 );
}