#how to get a bounding box for this
28 messages · Page 1 of 1 (latest)
i was using box 3 but
as u can see the right top corner is empty
so detection is detected but my sphere don't touch the square
i don't want something perfect
but not something big like this
Thank for any help
are you using a physics library or something?
or just creating a Box3 and checking for collisions manually?
the intersection types in three.js are pretty basic, i don't think there is arbitrary shape-on-shape intersection out of the box
lots of people use a physics library (ammojs, cannonjs, rapierjs) with three.js. Or you can do just collision detection with something like https://github.com/gkjohnson/three-mesh-bvh
im using box 3
and checking manually collision
i want to use the easiest way to make this and if possible not using another library
You could (manually) place boxes for each step, and collide against those. This requires figuring out where to put the boxes, three.js won't do that part for you. Or loop over all the triangles in the shape and check their distance from the sphere, with something like https://threejs.org/docs/index.html?q=triangle#api/en/math/Triangle.closestPointToPoint ... this would be fine for a simple shape like you show, but slow for more complex ones.
If neither of those sound like the right choice for you, I would recommend three-mesh-bvh.
i will try the first option
A bounding box by definition is a box, which encapsulates something. A box is defined as a cube, so a bounding box would not be able to get your exact shape, it's meant to be mostly use a a rough pass before any detailed collision detection.
You may be thinking of something that fits more into a collision/physics library, or a data structure like an octree. https://threejs.org/examples/?q=fps#games_fps
had forgotten about three/addons/math/Octree.js, that's a good option here probably 👍
i already saw this exemple and
To be honest i don't understand everything
Im a junior trying to make a CV/Portfolio
i'll try to learn about octree thank you !
A common approach to something that's "not perfect but better than a bounding box" is to create a simplified piece of geometry which isn't rendered, but is used for collisions, it's a common technique in game engines but may be a bit of a pain to implement in three. Stairs for instance are usually just a slope in games as far as collisions are concerned, one face representing all the steps so the player can glide up them when walking.
But octree might be a better path, or a physics library that takes care of it for you.
so octree allows me to do the yellow one ? if yes its perfect
there's nothing in three.js that's going to automatically turn those steps into a slope for you, other than creating a shape like that (e.g. in Blender) and loading it separately... kind of depends whether you want the player to ramp smoothly up the steps, or to hop up them, or what you have in mind.