I’m trying to raycast only to a collisionGroup, but the function throws an error when I pass the filterCollisionGroup as a parameter.
This is the part of my code where I make the raycast:
var result = this.app.systems.rigidbody.raycastFirst(from, to, {
filterCollisionGroup: pc.BODYGROUP_USER_2
});
And this is the error that I received:
If you pass the ‘options’ parameter to the raycastFirst of a Rigidbody it throws an error because at the end of that function is trying to use that parameter as a function:
raycastFirst(start, end, options = {}) {
// Tags and custom callback can only be performed by looking at all results.
if (options.filterTags || options.filterCallback) {
options.sort = true;
return this.raycastAll(start, end, options)[0] || null;
}
let result = null;
ammoRayStart.setValue(start.x, start.y, start.z);
ammoRayEnd.setValue(end.x, end.y, end.z);
const rayCallback = new Ammo.ClosestRayResultCallback(ammoRayStart, ammoRayEnd);
if (typeof options.filterCollisionGroup === 'number') {
rayCallback.set_m_collisionFilterGroup(options.filterCollisionGroup);
}
if (typeof options.filterCollisionMask === 'number') {
rayCallback.set_m_collisionFilterMask(options.filterCollisionMask);
}
this.dynamicsWorld.rayTest(ammoRayStart, ammoRayEnd, rayCallback);
if (rayCallback.hasHit()) {
const collisionObj = rayCallback.get_m_collisionObject();
const body = Ammo.castObject(collisionObj, Ammo.btRigidBody);
if (body) {
const point = rayCallback.get_m_hitPointWorld();
const normal = rayCallback.get_m_hitNormalWorld();
result = new RaycastResult(
body.entity,
new Vec3(point.x(), point.y(), point.z()),
new Vec3(normal.x(), normal.y(), normal.z()),
rayCallback.get_m_closestHitFraction()
);
// keeping for backwards compatibility
if (arguments.length > 2) {
Debug.deprecated('pc.RigidBodyComponentSystem#rayCastFirst no longer requires a callback. The result of the raycast is returned by the function instead.');
const callback = arguments[2];
callback(result);
}
}
}
Ammo.destroy(rayCallback);
return result;
}
This code is from the system.js of the rigidbodies
am I doing something wrong or is there a workaround?