Rays V. Physics

Started by
2 comments, last by JasonBlochowiak 16 years, 11 months ago
I'm Using Ogre(Eihort) NxOgre(0.6) PhysX(2.7.0). I need to make weapons for my game, if they didn't need much accuracy, i would just use Rays, but this game need accurate Ballistics, so i can't just go in a straight line! So i'm not sure whether to create a physics object and use that with a collision callback, or to use a ray and move it down slightly based on the distance. Help!
Advertisement
If you want to model your bullets as a fast moving point in space, I'd suggest using small rays or segments. Point moves from frame to frame at a given speed, and you check for ray intersection from the point position, with the point velocity, up to the frame time. It should be more efficient than using a small fast moving body, and probably as accurate. You have also to consider that using a standard body for your bullet can mean that you will force the engine checking collisions between bullets if you are not careful, and that's a no-no.

It also depends on the engine capabilities and how well they handle ray intersection detection. They can also have implemented a special optimised 'particle' mechanism, that does the ray/segment thing, and provides you with all the callbacks you need.

Everything is better with Metal.

At first glance, there is no reason why you can't treat it similarly to a "ray". It's path would still be described as a parametric equation, but would be quadratic rather than linear. You could even throw in something to account for drag, if you wanted to.

It would, however, add a lot of complexity to intersection tests.

In the end, oliii's suggestion is probably the best approach. Using discreet linear segments, per frame, is probably much more efficient. If you have to pre-compute the point of impact, it may not be.
You could use something like a swept sphere test, where the radius of the sphere represents a reasonable amount of ballistic arc for a segment. Depending on circumstances, you could do a few swept sphere segments to accomodate a larger arc. Then, if you got a hit within a given segment, you could do the piecewise linear ray testing that's been mentioned.

This topic is closed to new replies.

Advertisement