Collision detection in TypeScript with Box3 and Sphere is not working


The worst problems are for me if something does run without an error but simply does not work. So maybe someone can help me and tell me what i am doing wrong in my code.

Basically i am trying to detect collisions and have found a solution at the mozila dev side. Unfortunately it is not working so i think i have a misunderstanding here.

In my typescript code i have done the following:

     Param: sceneFile : string : path with filename to load 
    constructor(private gameObject: any) {
        this._scene = new Scene();
        this.arrOfObstcls = new Array<object>;

        // expand THREE.js Sphere to support collision tests vs Box3
        // we are creating a vector outside the method scope to
        // avoid spawning a new instance of Vector3 on every check
        Sphere.__closest = new Vector3();
        Sphere.prototype.intersectsBox = function (box: Mesh) {
        // get box closest point to sphere center by clamping
        Sphere.__closest.clamp(box.min, box.max);
        const distance =;
        return distance < this.radius * this.radius;

    private collision() {
        const playerBox = this._scene.getObjectByName('PlayerBoxObj');
        const knotBBox = new Box3(

        const specialPill = this._scene.getObjectByName('Pill3Obj');
        const knotBSphere = new Sphere(specialPill.position, 
                                       specialPill.geometry.boundingSphere.radius );

        if(knotBSphere.intersectsBox(knotBBox)) {
            console.log('Kontakt !!!');

the collision method is called in my update.function. But the collision is not logged to the console. What is the problem ?

Kind regards and happy new year :slight_smile:

Try using intersectsSphere afaik spheres use a spherical bounding volume which may be part of the issue but you may also need to call the function as