#how to get a bounding box for this

28 messages · Page 1 of 1 (latest)

dark vessel
#

or maybe another way to detect collision ?

#

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

tall stirrup
#

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

dark vessel
#

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

tall stirrup
#

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.

dark vessel
#

i will try the first option

quiet ember
#

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.

tall stirrup
#

had forgotten about three/addons/math/Octree.js, that's a good option here probably 👍

dark vessel
#

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 !

quiet ember
# dark vessel i don't want something perfect but not something big like this

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.

dark vessel
#

so octree allows me to do the yellow one ? if yes its perfect

tall stirrup
#

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.