-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollisionDetection.js
80 lines (55 loc) · 1.62 KB
/
collisionDetection.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function OBJmodel(size, position, name) {
this.size = size;
this.position = position;
this.name = name
this.minX = (this.position[0]-(this.size[0]/2));
this.maxX = (this.position[0]+(this.size[0]/2));
this.minY = (this.position[1]-(this.size[1]/2));
this.maxY = (this.position[1]+(this.size[1]/2));
/*var ifSoldier = 6;
if (this.name === "soldier" || this.name === "bullet")
ifSoldier = 6;*/
this.minZ = (this.position[2]-6-(this.size[2]/2));
this.maxZ = (this.position[2]-6+(this.size[2]/2));
this.detectCollision = function(b) {
if ((this.minX <= b.maxX && this.maxX >= b.minX) &&
(this.minY <= b.maxY && this.maxY >= b.minY) &&
(this.minZ <= b.maxZ && this.maxZ >= b.minZ)){
return this.getSide(b);
}
return;
};
this.getCollisionX = function(b) {
if(this.maxX>b.maxX){
}else{
}
return (this.position[0]+(this.size[2]/2));
};
this.setPosition = function(pos) {
this.position = pos;
this.minX = (this.position[0]-(this.size[0]/2));
this.maxX = (this.position[0]+(this.size[0]/2));
this.minY = (this.position[1]-(this.size[1]/2));
this.maxY = (this.position[1]+(this.size[1]/2));
this.minZ = (this.position[2]-(this.size[2]/2));
this.maxZ = (this.position[2]+(this.size[2]/2));
};
this.getSide = function(b) {
if(this.position[2] <= b.minZ){
console.log("Top");
return("top")
}
if(this.position[2] >= b.maxZ){
console.log("Down");
return("down")
}
if(this.position[0] < b.minX){
console.log("Left");
return("left");
}
if(this.position[0] > b.maxX){
console.log("Right");
return("right");
}
};
}