Hello, Im currently looking forward to implementing a simple AABB collision detection, however I can think of many different implementations, so I was wondering if there is any working sample, which I could leap off from. I want to implement in a 3D game with PointerLockControls for handling basic input. If anyone has any examples, please let me know!
Like this? Or without a physics engine?
If you just want to detect intersections of AABBs β and not simulate physics with them β then THREE.Box3 methods like setFromObject
and intersect
should be enough.
Just to expand on excellent @donmccurdy suggestion, you can use Box3
and Sphere
to implement axis-aligned boxes and bounding spheres respectively, since they have methods to do interesction test agains other volumes (i.e. other boxes and spheres). This approach is very usefull, specially if you need to cover sphere-to-box or sphere-to-sphere collissions.
A slightly different approach is to use raw BoxHelper
, where you can use its .setFromObject
method to link it with a regular mesh
object. The benefit of this is that the inner update() will keep it up to date with afine transformations to the linked mesh, and plus you can always render the helper geometry to debug collissions (ah! and behaves well with childrens also). The downside of this is that you donβt have sphere representations.
Mozilla game dev posted an article on all of this with working demos for the two approaches and all the combinations, I strongly recommend reading it as well as the introductory article on basics of 3D collision detection.