Bounding Box intersectsRay problem

var upPoleBBox = new pc.BoundingBox(this.upPole.getPosition(), this.upPole.sprite.aabb.halfExtents);
var downPoleBBox = new pc.BoundingBox(this.downPole.getPosition(), this.downPole.sprite.aabb.halfExtents);
var birdBBox = new pc.BoundingBox(this.bird.getPosition(), this.bird.sprite.aabb.halfExtents);
var rays = [
        new pc.Ray(birdBBox.getMin(), pc.Vec3.DOWN),    // bottom edge
        new pc.Ray(birdBBox.getMax(), pc.Vec3.RIGHT),  // right edge
        new pc.Ray(birdBBox.getMax(), pc.Vec3.UP),     // top edge
        new pc.Ray(birdBBox.getMin(), pc.Vec3.LEFT)    // left edge
    ];

    for (var i = 0; i < rays.length; i++) {
        if (upPoleBBox.intersectsRay(rays[i]) || downPoleBBox.intersectsRay(rays[i])) {
            console.log("collision detected");
            this.isHit = 1;
            var GAME = this.app.root.findByTag("game");
            var GAMEOVER = this.app.root.findByTag("go");

            GAME[0].enabled = false;
            setTimeout(function () {
                GAMEOVER[0].enabled = true;
            }, 350);
        }
    }

This code isn’t working fine. Is there any modifications that I need to do ?

var birdPos = this.bird.getPosition();

    var offset = new pc.Vec3(0.2, 0.2, 0.2);
    birdPos.add(offset);
    var ray = new pc.Ray(birdPos, pc.Vec3.FORWARD);
    if (downPoleBBox.intersectsRay(ray) || upPoleBBox.intersectsRay(ray)) {
        console.log("collision detected", downPoleBBox.intersectsRay(ray), upPoleBBox.intersectsRay(ray));
        this.isHit = 1;
        var GAME = this.app.root.findByTag("game");
        var GAMEOVER = this.app.root.findByTag("go");

        GAME[0].enabled = false;
        setTimeout(function () {
            GAMEOVER[0].enabled = true;
        }, 350);
    }

I have used this code also But didnt get proper collision

To allow the community to best help you, please create a small public project of the issue that you have like I did here in your last thread: How to draw bounding box of sprite with some color - #7 by yaustar

1 Like

its okay I solved it