Closed sbuys closed 1 month ago
will look into it thanks @sbuys
will look into it thanks @sbuys
don know how to approach this yet but I've thought about it
@sbuys
can you point me to part of code which does as you wrote
the logic for calculating offsets will resolve based on the final item in the calculation
@sbuys
can you point me to part of code which does as you wrote
the logic for calculating offsets will resolve based on the final item in the calculation
Sure:
https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L59
forEach(this.all(), (body: TBody) => {
this.separateBody(body, callback, response);
});
Each body calculates sequentially as it is called in forEach
@sbuys can you point me to part of code which does as you wrote
the logic for calculating offsets will resolve based on the final item in the calculation
Sure:
https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L59
forEach(this.all(), (body: TBody) => { this.separateBody(body, callback, response); });
Each body calculates sequentially as it is called in
forEach
I feel what you mean but, this is like the "dynamic body" in your picture
inside separateBody() there is checkOne() call and inside it the offsets are actually added
but in the case where circle is exactly between 2 quads the collisions vector to nullify collision will actually not nullify collision if you feel me
I will try to add at least a test for this in a couple of days
but still no solution on my side, especially since it was even written long time ago in the docs that: https://www.npmjs.com/package/detect-collisions/v/2.1.0#sometimes-bodies-can-squeeze-between-two-other-bodies-whats-going-on
inside separateBody() there is checkOne() call and inside it the offsets are actually added
https://github.com/Prozi/detect-collisions/blob/master/src/system.ts#L80-L95
only thing for now I can suggest is to do something like:
class MySystem extends System {
separate(...) {
// your implementation that does separate even if offset.x === 0 and offset.y === 0
}
}
and handle it how you feel you should, sorry
@Prozi Thanks for looking into it. I understand the complexity. I ended up solving this particular problem with a physics library. I do really like what you've done here and will use for other situations.
@sbuys thank you I think I will close this for now
When multiple collisions are detect simultaneously, resolutions offset each other because they are handled sequentially.
Given the above situation, I would expect
system.separate()
to move the blue dynamic body out of both static body areas. But the logic for calculating offsets will resolve based on the final item in the calculation.Further, when calling
system.checkAll()
orsystem.checkOne(...)
after callingsystem.separate(),
the library does not detect any remaining collisions.In this example, the blue circles are static bodies, the red dashed boxes are the initial placement of dynamic bodies and the blue solid boxes are the positions resolved by the library. You can see in the magenta box that "Harrisburg" correctly resolves the collisions in its area, moving below the static circle body.
But "Portland" does not resolve correctly. The dynamic rect still intersects with the static circle. The resolution from the "Seattle" collision is overriding the "Portland" resolution.
It seems like
system.separate()
should account for multiple simultaneous intersections and resolve them in whole. Is there a recommended approach for tackling situations like this?