tomaspietravallo / sparkar-volts

An extensive Typescript framework that eases the development experience in Meta Spark AR
https://tomaspietravallo.gitbook.io/sparkar-volts/how-to-use-volts
MIT License
22 stars 1 forks source link

OBB Collision response #18

Open tomaspietravallo opened 2 years ago

tomaspietravallo commented 2 years ago

Find MTV from axis overlap. Can be found within the againstOBB method, so that the axis do not need to be all tested again

https://github.com/tomaspietravallo/sparkar-volts/blob/7983ce36995540d0b53e95f0aa5a4238cb591037/volts.ts#L2087-L2094

tomaspietravallo commented 2 years ago

Idea. This is just going from vibes, proof that this is correct for most situations remains to be found. From visual tests within Spark AR Studio it seems to hold for collisions in two axis.

const { overlap, axis } = obbA.againstOBB(obbA);

objA.pos.add(objA.vel.copy().mul(objA.vel.copy().normalize().dot(axis) * -overlap));
objB.pos.add(objB.vel.copy().mul(objB.vel.copy().normalize().dot(axis) * -overlap));
tomaspietravallo commented 2 years ago

The idea above works well enough, but the current methods for solveCollision don't look realistic. Whether the overlap correction is needed after fixing this COR issue remains to be seen

https://en.wikipedia.org/wiki/Coefficient_of_restitution#Derivation

Side note: testAxiss can be reduced and optimized