Raycast As A Shape

Hey It’s me again. So I’m having another small problem and I’m not even sure what to call it. I would like to cast a ray, with the ray having the shape of an object. Don’t worry, I brought a couple of crude diagrams to show what I mean!
this
The Blue object represents the shape I would like to cast, which is a model in my game.
The Red object represents the ray being cast
The Green object represents obstacles that would be returned when the shaped-ray hits them. I wanted this in order to raycast between objects and register hits with what’s behind them.
Here’s another example:
and%20this
If you need a more practical example, consider raycasted throwing stones against an armored foe with open weak points. I’d like larger stones to be raycasted in the shape of the stone to bounce off the armor, while stones smaller than the openings in the armor (the weak points) are able to pass through.

As always, thanks in advance for your feedback!
(PS if there is some other way to achieve this with some measure of accuracy, maybe with collisions or something, feel free to share alternate solutions!)

Hmm… Depending on the degree of accuracy that you want, you could perhaps emulate this via multiple ordinary raycasts. More raycasts, better fitted to the model, would produce more-accurate results–but you’d have to test the method to see how well it performed. Fewer raycasts would be less accurate, but should perform well on modern hardware, I imagine.

Otherwise, this looks a lot like a “sweep test”–roughly speaking, the desired object is “extruded” in the desired direction, and the test is made against this extrusion.

Panda’s internal collision system has an approach that achieves more or less the effect of this, via moving the object to be tested multiple times per update and testing with each move, if I’m not much mistaken. You can read more about this in this manual page, I believe.

Bullet has a method to do this in the “BulletWorld” class–see the API here. Note that it apparently requires a convex shape, which your example above isn’t, if I’m not much mistaken.

All that said, in your practical example I think that I’d likely just use ordinary collision, with the stone likely represented by a simple collision-shape–a sphere if it’s slow, and a raycast or tube/cylinder if it’s fast. (Or a sweep-test if the tube solution proves too slow in the latter case.) I might then use standard non-physics logic to test the size of the stone against the size of the weak point. If the “stone size” is larger than the “weak point size”, I might have the stone bounce off harmlessly; if not, I might register a hit, instead.

Thank you for the reply! These are definitely good ideas that I’m going to be looking into. I didn’t realize quite how fully-featured the Panda3D Collision System was. Out of curiosity, is there a collision shape that uses the geometry of a model instead of a preset shape? A lot of my models are low-poly, but are are quite unusually shaped(Like the T up there). Unfortunately, the weak point sizes are dynamic, and their size depends on things like armor design and eventually player-modded parts.

There’s the “CollisionPolygon” shape, which can be used to build up a shape by hand, or constructed in the background for you from an imported 3D model as with normal geometry, I believe.

However, note that I don’t think that you can use a “CollisionPoly” object as a “from” collision-object, only an “into” collision object.

See here for more information.

If a close match to the object’s shape is important, then one possible workaround is to approximate your object using multiple simpler shapes. For example, your “T”-shaped object above might be approximated with two cylinders, or two boxes.

If simpler approximations won’t work, then you might want to look into Bullet–I’m not sure of whether it handles arbitrary shapes, but it’s possible that it does, and it seems worth checking.

That should work perfectly well with the size-comparison that I mentioned above, I would imagine! After all, the size of the weak-point, even if generated dynamically, is likely known or calculable, and can thus be used in comparisons within your logic.