Got a quick (but possibly difficult?) question I’m struggling with. With my first person space sim, I’m trying to draw a box 2d box around other ships (which are 3d models). The idea is that this represents a targeting system; a thin, dull box for other targets with a bright red box for enemies.
What’s the best way to draw this box around the target? How can I make it appear correctly on the player’s “cockpit”? Is there an easy way to do this?
One way that I thought about is creating a sprite with a texture around the outside and parenting it to the enemy, which would technically work, but would cause problems as the line would get thinner or thicker depending on how far away the target is… I’d prefer it if the line thickness remained steady.
A neat feature would be the box being literally drawn around the enemy ship instead of being square- so if the ship had a large broadside profile it would be a large box, but if it had a narrow portrait profile it would have a small box… hmm.
one feature that would be nice would be if you could define in which viewspace the getTightBounds works. afaik the current implementation gives coordinates in world-space (x/y min&max).
if you could get the relative min&max x/y relative to the camera it would be more useful.
I gave it a shot- I couldn’t get the solutions proposed above to work as I kept getting coordinates way, way off the 2d screen such as -11… but I solved the original problem by simply creating a 3D cube as each ship was created, setting it to wireframe then parenting it to the ship and hiding/changing the colour as necessary.
This solution seems to work pretty well, except that the wireframe rendering mode shows the ‘cross sections’ of the cube (AKA lines running from the corners along each face) which does bad things for the visual effect. It’s otherwise perfect (although I can’t see any way to increase the line thickness without adding a second, slightly smaller cube…)
Hmm, I don’t think that’s possible (I could be wrong tho)
It wouldn’t be hard to implement though, we could maybe add a set_color function to ShowBoundsEffect.
We could, but that would be silly. The purpose of the ShowBoundsEffect is to aid developers in viewing the bounding volumes, it’s not intended to be a visually pleasing effect. It’s not really optimized for production code.
If you want to draw a bounding box in the color of your choosing, I recommend constructing the box you want directly.
Well, I only seem to be having one more trouble now- maybe I’m doing something wrong, but the “centre” of the 2d objects is off. It seems like the object is incorrectly assigning the centre to be the bottom left hand corner of the image- is this a known issue or am I doing something wrong?
Thanks for the continuing help guys. I really appreciate it.