Excalibur
Excalibur copied to clipboard
Support arbitrary raycasting into a Scene
Context
Currently you must have a reference to a collider in order to perform a raycast against it, this quickly becomes slow, unwieldy, or impractical if a scene has many colliders.
Proposal
Add a way off of scene to raycast arbitrarily and get results
Possible sketch
const scene = game.currentScene;
const ray = new ex.Ray(ex.vec(100, 100), ex.Vector.Right);
const maxDistance = 100; // pixels
const hitResults: RayCastResults[] = scene.physicsWorld.rayCast(ray, maxDistance);
// list sorted by distance least to greatest?
console.log(hitResults[0].distance); // distance in pixels
console.log(hitResults[0].collider); // collider that was intersected
console.log(hitResults[0].point); // world space point that was intersected
This looks like a good approach to me!
The only other suggestions I might have is some way to filter out by collision groups. I might want to just raycast against a "floor" group, for example. That could either be an option passed to the raycast (the collision group/name), or if there's a way to get all colliders from a collision group I could cross-reference them with the hitResults (though that could involve a lot of iterating).
Good point, maybe this where we can pass an optional option bag with the various configurations?
const floorGroup = ex.CollisionGroupManager.create("floor");
scene.physicWorld.rayCast(ray, {
maxDistance: 100,
collisionGroups: [floorGroup]
})
@eonarheim I like that!
This issue hasn't had any recent activity lately and is being marked as stale automatically.