What exactly does systems.rigidbody.raycastFirst do?

I’m just trying to understand the code systems.rigidbody.raycastFirst. It sounds like the entire engine is raycasting from every single rigidbody in the scene? Is that correct? Or is it just casting a single ray from from to to, but globally from the engine?

I am using that function like this

from = this.camera.camera.screenToWorld(event.x, event.y, this.camera.camera.nearClip);
to = this.camera.camera.screenToWorld(event.x, event.y, this.camera.camera.farClip);
result = this.engine.systems.rigidbody.raycastFirst(from, to);

It works fine, I just cannot understand what this.engine.systems.rigidbody.raycastFirst is really doing.

Yes, the function applies to the whole physics world (and every rigidbody within it). The physics world is created and managed by the RigidBodyComponentSystem, which is accessed as this.app.systems.rigidbody.

This engine-only example shows the use of both raycastFirst and raycastAll:

http://playcanvas.github.io/#physics/raycast.html

(By the way, I’m not sure what this.engine is…you should be using this.app to access the Application instance from a script)