Raycast through multiple entities

You will have to look into the Bullet API and what is exposed in ammo.js.

I wrote a few scripts and functions in this game but I no longer have access to the whole source. This what I can get from the site:

Script filter

var PhysicsFilter = pc.createScript("physicsFilter");
PhysicsFilter.attributes.add("groupDefault", {
    type: "boolean",
    title: "Group Default",
    "default": !0
}),
PhysicsFilter.attributes.add("groupRagDoll", {
    type: "boolean",
    title: "Group RagDoll",
    "default": !1
}),
PhysicsFilter.attributes.add("groupEnvironment", {
    type: "boolean",
    title: "Group Environment",
    "default": !1
}),
PhysicsFilter.attributes.add("groupSummonObject", {
    type: "boolean",
    title: "Group SummonObject",
    "default": !1
}),
PhysicsFilter.attributes.add("groupSupport", {
    type: "boolean",
    title: "Group Support",
    "default": !1
}),
PhysicsFilter.attributes.add("groupTrain", {
    type: "boolean",
    title: "Group Train",
    "default": !1
}),
PhysicsFilter.attributes.add("groupMisc", {
    type: "boolean",
    title: "Group Misc",
    "default": !1
}),
PhysicsFilter.attributes.add("groupRain", {
    type: "boolean",
    title: "Group Rain",
    "default": !1
}),
PhysicsFilter.attributes.add("maskDefault", {
    type: "boolean",
    title: "Mask Default",
    "default": !0
}),
PhysicsFilter.attributes.add("maskRagDoll", {
    type: "boolean",
    title: "Mask RagDoll",
    "default": !1
}),
PhysicsFilter.attributes.add("maskEnvironment", {
    type: "boolean",
    title: "Mask Environment",
    "default": !1
}),
PhysicsFilter.attributes.add("maskSummonObject", {
    type: "boolean",
    title: "Mask SummonObject",
    "default": !1
}),
PhysicsFilter.attributes.add("maskSupport", {
    type: "boolean",
    title: "Mask Support",
    "default": !1
}),
PhysicsFilter.attributes.add("maskTrain", {
    type: "boolean",
    title: "Mask Train",
    "default": !1
}),
PhysicsFilter.attributes.add("maskMisc", {
    type: "boolean",
    title: "Mask Misc",
    "default": !1
}),
PhysicsFilter.attributes.add("maskRain", {
    type: "boolean",
    title: "Mask Rain",
    "default": !1
}),
PhysicsFilter.DEFAULT = 8,
PhysicsFilter.RAGDOLL = 16,
PhysicsFilter.ENVIRONMENT = 32,
PhysicsFilter.SUMMON_OBJECT = 64,
PhysicsFilter.SUPPORT = 128,
PhysicsFilter.TRAIN = 256,
PhysicsFilter.MISC = 512,
PhysicsFilter.RAIN = 1024,
PhysicsFilter.prototype.initialize = function() {
    this.entity.rigidbody.group = (this.groupDefault ? PhysicsFilter.DEFAULT : 0) | (this.groupRagDoll ? PhysicsFilter.RAGDOLL : 0) | (this.groupEnvironment ? PhysicsFilter.ENVIRONMENT : 0) | (this.groupSummonObject ? PhysicsFilter.SUMMON_OBJECT : 0) | (this.groupSupport ? PhysicsFilter.SUPPORT : 0) | (this.groupTrain ? PhysicsFilter.TRAIN : 0) | (this.groupMisc ? PhysicsFilter.MISC : 0) | (this.groupRain ? PhysicsFilter.RAIN : 0),
    this.entity.rigidbody.mask = (this.maskDefault ? PhysicsFilter.DEFAULT : 0) | (this.maskRagDoll ? PhysicsFilter.RAGDOLL : 0) | (this.maskEnvironment ? PhysicsFilter.ENVIRONMENT : 0) | (this.maskSummonObject ? PhysicsFilter.SUMMON_OBJECT : 0) | (this.maskSupport ? PhysicsFilter.SUPPORT : 0) | (this.maskTrain ? PhysicsFilter.TRAIN : 0) | (this.maskMisc ? PhysicsFilter.MISC : 0) | (this.maskRain ? PhysicsFilter.RAIN : 0)
}
;

Function

    var n = new Ammo.btVector3
      , t = new Ammo.btVector3
      , e = function(n, t, e) {
        this.entity = n,
        this.point = t,
        this.normal = e
    };
    pc.RigidBodyComponentSystem.prototype.raycastFiltered = function(o, i, r, a) {
        n.setValue(o.x, o.y, o.z),
        t.setValue(i.x, i.y, i.z);
        var l = new Ammo.ClosestRayResultCallback(n,t);
        l.set_m_collisionFilterGroup(r),
        l.set_m_collisionFilterMask(a),
        this.app.systems.rigidbody.dynamicsWorld.rayTest(n, t, l);
        var s = null;
        if (l.hasHit()) {
            var u = l.get_m_collisionObject()
              , c = Ammo.castObject(u, Ammo.btRigidBody)
              , m = l.get_m_hitPointWorld()
              , d = l.get_m_hitNormalWorld();
            c && (s = new e(c.entity,new pc.Vec3(m.x(),m.y(),m.z()),new pc.Vec3(d.x(),d.y(),d.z())))
        }
        return Ammo.destroy(l),
        s
    }