-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspawnCube2.js
More file actions
80 lines (68 loc) · 1.84 KB
/
Copy pathspawnCube2.js
File metadata and controls
80 lines (68 loc) · 1.84 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(function(){
var cubeList = [];
var TRIGGER_CONTROLS = [
Controller.Standard.LT,
Controller.Standard.RT,
];
var hand;
var _this;
var drawLine = function (startPos, endPos) {
var id = Entities.addEntity({
position: startPos,
type: "Box",
name: "LineBox",
color: { red: 0, green: 255, blue: 155 }
});
print("step 4");
};
function CubeSpawner(){};
print("step 1");
CubeSpawner.prototype = {
preload: function(entityID){
_this = this;
_this.entityID = entityID;
this.entityID = entityID;
print("step 2");
_this.lineManager = LineManager();
},
startEquip: function(entityID, args){
print("Equipping");
hand = args[0] == "left" ? 0:1;
},
continueEquip: function(entityID, args){
if(Controller.getValue(TRIGGER_CONTROLS[hand]) > .95)
{
var cubePosition = frontPosition();
print("step 3");
drawLine(cubePosition, cubePosition);
}
}
};
var spawnACube = function(){
var cubePosition = frontPosition();
var id = Entities.addEntity({
position: cubePosition,
"script": Script.resolvePath("cube.js") ,
type: "Box",
name: "ScriptBox",
color: { red: 0, green: 0, blue: 155 }
});
print("Made a cube!" , id);
cubeList.push(id);
};
var frontPosition = function(){
var position = Entities.getEntityProperties(_this.entityID).position;
var rotation = Entities.getEntityProperties(_this.entityID).rotation;
var front = Quat.getFront(rotation);
var offset = Vec3.multiply(front, 0.25);
return Vec3.sum(position, offset);
}
var deleteAllCubes = function(){
while(cubeList.length > 0)
{
Entities.deleteEntity(cubeList.pop());
}
}
Entities.deletingEntity.connect(deleteAllCubes);
return new CubeSpawner();
});