Fix step 1
@@ -59,9 +59,9 @@ class Collider
59
59
var hw = this.gameObject.transform.size.x / 2;
60
60
var hh = this.gameObject.transform.size.y / 2;
61
61
62
if(point.x > this.transform.position.x - hw && point.x < this.transform.position.x + hw)
62
if(point.x > this.gameObject.transform.position.x - hw && point.x < this.gameObject.transform.position.x + hw)
63
63
{
64
if(point.y > this.transform.position.y - hh && point.y < this.transform.position.y + hh)
64
if(point.y > this.gameObject.transform.position.y - hh && point.y < this.gameObject.transform.position.y + hh)
65
65
{
66
66
return true;
67
67
}
@@ -59,9 +59,9 @@ class Collider59
var hw = this.gameObject.transform.size.x / 2;59
var hw = this.gameObject.transform.size.x / 2;60
var hh = this.gameObject.transform.size.y / 2;60
var hh = this.gameObject.transform.size.y / 2;61
61
62
if(point.x > this.transform.position.x - hw && point.x < this.transform.position.x + hw)62
if(point.x > this.gameObject.transform.position.x - hw && point.x < this.gameObject.transform.position.x + hw)63
{63
{64
if(point.y > this.transform.position.y - hh && point.y < this.transform.position.y + hh)64
if(point.y > this.gameObject.transform.position.y - hh && point.y < this.gameObject.transform.position.y + hh)65
{65
{66
return true;66
return true;67
}67
}@@ -18,18 +18,19 @@ class Ray
18
18
new vector(scene.activeObjects[i].transform.position.x + hw, scene.activeObjects[i].transform.position.y + hh)
19
19
]
20
20
21
for(let p = 0; o < points.length; p++)
21
for(let p = 0; p < points.length; p++)
22
22
{
23
let point = points[p].subtract(origin);
23
let point = points[p];
24
let deltaDistance = point.subtract(origin).length;
24
25
direction = direction.normalize();
25
26
26
let stretched = direction.stretch(Math.min(point.length, maxLength >= 0? maxLength : point.length))
27
let stretched = direction.stretch(Math.min(deltaDistance, maxLength > 0? maxLength : deltaDistance))
27
28
28
29
let calcPoint = origin.add(stretched);
29
30
30
31
if(scene.activeObjects[i].collider.isInBounds(calcPoint))
31
32
{
32
hits.push({hitObj: scene.activeObjects[i], hitPoint: new vector(0, 0)})
33
hits.push({hitObj: scene.activeObjects[i], hitPoint: calcPoint})
33
34
}
34
35
}
35
36
}
@@ -18,18 +18,19 @@ class Ray18
new vector(scene.activeObjects[i].transform.position.x + hw, scene.activeObjects[i].transform.position.y + hh)18
new vector(scene.activeObjects[i].transform.position.x + hw, scene.activeObjects[i].transform.position.y + hh)19
]19
]20
20
21
for(let p = 0; o < points.length; p++)21
for(let p = 0; p < points.length; p++)22
{22
{23
let point = points[p].subtract(origin);23
let point = points[p];24
let deltaDistance = point.subtract(origin).length;24
direction = direction.normalize();25
direction = direction.normalize();25
26
26
let stretched = direction.stretch(Math.min(point.length, maxLength >= 0? maxLength : point.length))27
let stretched = direction.stretch(Math.min(deltaDistance, maxLength > 0? maxLength : deltaDistance))27
28
28
let calcPoint = origin.add(stretched);29
let calcPoint = origin.add(stretched);29
30
30
if(scene.activeObjects[i].collider.isInBounds(calcPoint))31
if(scene.activeObjects[i].collider.isInBounds(calcPoint))31
{32
{32
hits.push({hitObj: scene.activeObjects[i], hitPoint: new vector(0, 0)})33
hits.push({hitObj: scene.activeObjects[i], hitPoint: calcPoint})33
}34
}34
}35
}35
}36
}@@ -12,10 +12,10 @@ class vector
12
12
13
13
get length()
14
14
{
15
return this.length();
15
return Math.sqrt((this.x * this.x) + (this.y * this.y));
16
16
}
17
17
18
length()
18
getLength()
19
19
{
20
20
return Math.sqrt((this.x * this.x) + (this.y * this.y));
21
21
}
@@ -31,9 +31,9 @@ class vector
31
31
{
32
32
var newVector = this.getCopy();
33
33
34
if(newVector.length() != 0)
34
if(newVector.length != 0)
35
35
{
36
var length = newVector.length();
36
var length = newVector.length;
37
37
newVector.x /= length;
38
38
newVector.y /= length;
39
39
}
@@ -55,7 +55,7 @@ class vector
55
55
var dX = this.x - otherVector.x;
56
56
var dY = this.y - otherVector.y;
57
57
58
return new vector(dX, dY).length();
58
return new vector(dX, dY).length;
59
59
}
60
60
61
61
@@ -12,10 +12,10 @@ class vector12
12
13
get length()13
get length()14
{14
{15
return this.length();15
return Math.sqrt((this.x * this.x) + (this.y * this.y));16
}16
}17
17
18
length()18
getLength()19
{19
{20
return Math.sqrt((this.x * this.x) + (this.y * this.y));20
return Math.sqrt((this.x * this.x) + (this.y * this.y));21
}21
}@@ -31,9 +31,9 @@ class vector31
{31
{32
var newVector = this.getCopy();32
var newVector = this.getCopy();33
33
34
if(newVector.length() != 0)34
if(newVector.length != 0)35
{35
{36
var length = newVector.length();36
var length = newVector.length;37
newVector.x /= length;37
newVector.x /= length;38
newVector.y /= length;38
newVector.y /= length;39
}39
}@@ -55,7 +55,7 @@ class vector55
var dX = this.x - otherVector.x;55
var dX = this.x - otherVector.x;56
var dY = this.y - otherVector.y;56
var dY = this.y - otherVector.y;57
57
58
return new vector(dX, dY).length();58
return new vector(dX, dY).length;59
}59
}60
60
61
61