Help with pickRay origin position


#1

Hey, guys. So I’m having an issue with pickRays where it doesn’t register the origin point of an entity unless set to the avatar’s position. What I’m trying to achieve is a ray to be drawn from a particle effect as soon as it spawns and deletes any entities in the path. I’ve written a script that resolves to the particle effect with a ray drawing upwards and a few box entities for testing, but nothing happens when the particle spawns.

(function () {
var _this = this;

destroyBlock = function () {
    _this = this;

    _this.CheckBlocks();
}

destroyBlock.prototype = {
    CheckBlocks: function () {
        var pickRay = {
            origin: _this.position,
            direction: Quat.getUp(_this.rotation)
        }

        var Intersection = Entities.findRayIntersection(pickRay);

        if (Intersection.intersects) {
            Entities.deleteEntity(intersection.entityID);
        }
    }
};

return new destroyBlock();

});


#2

this.position does not exist for entities and reliance on it can be troublesome later on as the same script runs for every single instance of the object, instead you to do callbacks.

You have to get the entity id from the preload event, and then use props = Entities.getEntityProperties(<id>) which after you can get the position of the object.

More info on the specifics Beyond the Wall of Scripts: Scripting in High Fidelity - Primer for Intermediate Programmers under entity scripts.


#3

Thanks you! This method worked perfectly!