Is there anyway to add a collider to a nodetransform?

running babylon in headless mode, creating many meshes using mesh.createbox has huge overhead instead im using transform node, though these nodes dont have colliders which i need for further calculations… is there anyway to add colliders to the nodes and specify collider dimensions?

Hi @tommox86
Have you tried using empty meshes?

new BABYLON.Mesh()

I do not think so as collider requires an AbstractMesh.

Adding @RaananW and @Cedric FYI

adding a mesh and setting mesh.isVisible = false seems to add the collider though its invisible to raycasts. anyway to raycast non rendered meshes?

you could create and empty mesh ? new BABYLON.Mesh instead of creating cubes or real geometry ?

The reason a collider required an abstract mesh is the bounding info (which is not available at a transform node level).

An invisible (and enabled!) mesh is a valid collider.

You can emulate the bounding info, but you can’t sadly skip the vertices test (done in _collideForSubMesh in AbstractMesh). You can technically emulate the entire thing and work with colliders only, but just creating the Geometries of all meshes will probably take you longer than simply creating a box mesh.

1 Like

ok, though when i set the mesh to isVisible = false and hit it with a raycast, nothing is returned. only when isVisible = true is the picked mesh returned.

Raycasting is not the collision system. I guess we are talking about two different things.

If you want raycasting to work you will need to set the predicate correctly. The default predicate checks that the mesh is enabled, pickable, and visible (check scene.pointerMovePredicate, scene.pointerUpPredicate and scene.pointerDownPredicate)

ok though im not using pointerdown for the ray.
var ray = new BABYLON.Ray(origin, direction, length);
this is for serverside code so ill be shooting a ray from one object to another. how would i go about setting the predicate for this?

scene.pickWithRay's signature is this:

    /** Use the given ray to pick a mesh in the scene
     * @param ray The ray to use to pick meshes
     * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must have isPickable set to true
     * @param fastCheck defines if the first intersection will be used (and not the closest)
     * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected
     * @returns a PickingInfo
    public pickWithRay(ray: Ray, predicate?: (mesh: AbstractMesh) => boolean, fastCheck?: boolean,
        trianglePredicate?: TrianglePickingPredicate): Nullable<PickingInfo>

The second variable is the predicate. it is a function that should return true for each mesh that should be checked for collision.


legend! thanks worked…