Closed tmanninger closed 1 year ago
My current dirty lifehack:
Instead auf using system.update():
for (let body of this._collisionSystem.all()) {
this._collisionSystem.updateBody(body)
if (body instanceof Line) {
if (body.points[0].x < body.points[1].x) {
body.minX = body.points[0].x
body.maxX = body.points[1].x
}
else {
body.minX = body.points[1].x
body.maxX = body.points[0].x
}
if (body.points[0].y < body.points[1].y) {
body.minY = body.points[0].y
body.maxY = body.points[1].y
}
else {
body.minY = body.points[1].y
body.maxY = body.points[0].y
}
}
}
the reason @tmanninger is that in javascript 229.052 - 69.7 + 69.7 === 229.05199999999996
:smiling_face_with_tear:
your implementation ignores padding and line position
Ok thanks for feedback!
@Prozi other question (i know this is not issue related): Is there a way to update a Line object without adding it to the system object?
i will create a new Line object, update the attributes, check if there is a collision with the Line object. After this, the line object is not longer needed. My current way: 1.) Create Line object 2.) Add it to system 3.) call system.update(line) 4.) Check collision with another object. 5.) Delete line from system.
@Prozi other question (i know this is not issue related): Is there a way to update a Line object without adding it to the system object?
i will create a new Line object, update the attributes, check if there is a collision with the Line object. After this, the line object is not longer needed. My current way: 1.) Create Line object 2.) Add it to system 3.) call system.update(line) 4.) Check collision with another object. 5.) Delete line from system.
you can either
// this is the way to go skip step 3 (adding to system is same as updating body) skip step 5 (just remove line from system, but keep it for reuse if you plan to do this again)
or
you can just try to do 1) const line = new Line({}, {}) 2) system.all().filter((body) => body !== line && this.checkCollision(line, body))
but I dont recommend this unless you have a very small number of bodies as BVH is always faster for idk >100 bodies?
closing as [wont-fix] (the issue described in https://github.com/Prozi/detect-collisions/issues/47#issuecomment-1377062769 )
I create the following line:
After system.update(), the min/max auf the body have the following values:
Why is maxY rounded to
229.05199999999996
?Now, when i check, if on position
{ x: 600.51305, y: 229.052 }
is a collision, the check returns false.See example (see console output): https://codesandbox.io/s/proud-snowflake-04p5nh?file=/src/App.tsx:352-459