add terrain collision

This commit is contained in:
2024-12-23 18:30:59 +09:00
parent ae6f4c2847
commit 37a77e902c
5 changed files with 51 additions and 24 deletions
+2 -6
View File
@@ -23,10 +23,6 @@ export default class Terrain {
state() {
return {
...this,
position: {
x: this.x,
y: this.y,
},
}
}
@@ -41,8 +37,8 @@ export default class Terrain {
const indicesToPolygon = (indices) => {
const satPoints = [
new SAT.Vector(...points.shape[indices[0]].toArray()),
new SAT.Vector(...points.shape[indices[1]].toArray()),
new SAT.Vector(...points.shape[indices[2]].toArray()),
new SAT.Vector(...points.shape[indices[1]].clone().sub(points.shape[indices[0]]).toArray()),
new SAT.Vector(...points.shape[indices[2]].clone().sub(points.shape[indices[0]]).toArray()),
]
return new SAT.Polygon(satPoints[0], [new SAT.Vector(), satPoints[1], satPoints[2]])