BlueGit

timfa frameworkv3

thing colllider

timfa wsadhelios · pushed by timfa

Authored 2022-10-20 · 4 years ago

Hash
2a2a24bc172d15c99ad818541fdcab297fde157b
Parent
d21347d7
1 file changed +10 −31
framework/engine/objectComponents/collider.js +10 −31
@@ -102,42 +102,21 @@ class Collider
102 102 var ohh = o2.transform.size.y / 2;
103 103
104 104 //CHECK FROM OBJ PERSPECTIVE
105 var p =
105 var points =
106 106 [
107 [this.gameObject.transform.position.x - hw, this.gameObject.transform.position.y - hh],
108 [this.gameObject.transform.position.x + hw, this.gameObject.transform.position.y - hh],
109 [this.gameObject.transform.position.x - hw, this.gameObject.transform.position.y + hh],
110 [this.gameObject.transform.position.x + hw, this.gameObject.transform.position.y + hh]
107 [this.gameObject.transform.position.x - hw, this.gameObject.transform.position.y - hh], // topleft
108 [this.gameObject.transform.position.x + hw, this.gameObject.transform.position.y - hh], // topright
109 [this.gameObject.transform.position.x - hw, this.gameObject.transform.position.y + hh], // bottomleft
110 [this.gameObject.transform.position.x + hw, this.gameObject.transform.position.y + hh] // bottomright
111 111 ];
112 112
113 for (var pi = 0; pi < p.length; pi++)
113 if (points[0][0] >= o2.transform.position.x - ohw && points[0][0] <= o2.transform.position.x + ohw ||
114 points[0][1] >= o2.transform.position.x - ohw && points[0][0] <= o2.transform.position.x + ohw)
114 115 {
115 if (p[pi][0] > o2.transform.position.x - ohw && p[pi][0] < o2.transform.position.x + ohw)
116 if (points[2][0] > o2.transform.position.y - ohh && points[0][0] <= o2.transform.position.x + ohh ||
117 points[2][1] >= o2.transform.position.y - ohh && points[2][0] <= o2.transform.position.y + ohh)
116 118 {
117 if (p[pi][1] > o2.transform.position.y - ohh && p[pi][1] < o2.transform.position.y + ohh)
118 {
119 hit = true;
120 }
121 }
122 }
123
124 //CHECK FROM OTHER PERSPECTIVE
125 var p =
126 [
127 [o2.transform.position.x - ohw, o2.transform.position.y - ohh],
128 [o2.transform.position.x + ohw, o2.transform.position.y - ohh],
129 [o2.transform.position.x - ohw, o2.transform.position.y + ohh],
130 [o2.transform.position.x + ohw, o2.transform.position.y + ohh]
131 ];
132
133 for (var pi = 0; pi < p.length; pi++)
134 {
135 if (p[pi][0] > this.gameObject.transform.position.x - hw && p[pi][0] < this.gameObject.transform.position.x + hw)
136 {
137 if (p[pi][1] > this.gameObject.transform.position.y - hh && p[pi][1] < this.gameObject.transform.position.y + hh)
138 {
139 hit = true;
140 }
119 hit = true;
141 120 }
142 121 }
143 122
@@ -102,42 +102,21 @@ class Collider
102 var ohh = o2.transform.size.y / 2;
102 var ohh = o2.transform.size.y / 2;
103
103
104 //CHECK FROM OBJ PERSPECTIVE
104 //CHECK FROM OBJ PERSPECTIVE
105 var p =
105 var points =
106 [
106 [
107 [this.gameObject.transform.position.x - hw, this.gameObject.transform.position.y - hh],
107 [this.gameObject.transform.position.x - hw, this.gameObject.transform.position.y - hh], // topleft
108 [this.gameObject.transform.position.x + hw, this.gameObject.transform.position.y - hh],
108 [this.gameObject.transform.position.x + hw, this.gameObject.transform.position.y - hh], // topright
109 [this.gameObject.transform.position.x - hw, this.gameObject.transform.position.y + hh],
109 [this.gameObject.transform.position.x - hw, this.gameObject.transform.position.y + hh], // bottomleft
110 [this.gameObject.transform.position.x + hw, this.gameObject.transform.position.y + hh]
110 [this.gameObject.transform.position.x + hw, this.gameObject.transform.position.y + hh] // bottomright
111 ];
111 ];
112
112
113 for (var pi = 0; pi < p.length; pi++)
113 if (points[0][0] >= o2.transform.position.x - ohw && points[0][0] <= o2.transform.position.x + ohw ||
114 points[0][1] >= o2.transform.position.x - ohw && points[0][0] <= o2.transform.position.x + ohw)
114 {
115 {
115 if (p[pi][0] > o2.transform.position.x - ohw && p[pi][0] < o2.transform.position.x + ohw)
116 if (points[2][0] > o2.transform.position.y - ohh && points[0][0] <= o2.transform.position.x + ohh ||
117 points[2][1] >= o2.transform.position.y - ohh && points[2][0] <= o2.transform.position.y + ohh)
116 {
118 {
117 if (p[pi][1] > o2.transform.position.y - ohh && p[pi][1] < o2.transform.position.y + ohh)
119 hit = true;
118 {
119 hit = true;
120 }
121 }
122 }
123
124 //CHECK FROM OTHER PERSPECTIVE
125 var p =
126 [
127 [o2.transform.position.x - ohw, o2.transform.position.y - ohh],
128 [o2.transform.position.x + ohw, o2.transform.position.y - ohh],
129 [o2.transform.position.x - ohw, o2.transform.position.y + ohh],
130 [o2.transform.position.x + ohw, o2.transform.position.y + ohh]
131 ];
132
133 for (var pi = 0; pi < p.length; pi++)
134 {
135 if (p[pi][0] > this.gameObject.transform.position.x - hw && p[pi][0] < this.gameObject.transform.position.x + hw)
136 {
137 if (p[pi][1] > this.gameObject.transform.position.y - hh && p[pi][1] < this.gameObject.transform.position.y + hh)
138 {
139 hit = true;
140 }
141 }
120 }
142 }
121 }
143
122