Experimenting with perspective distortion and 2D elements

For a while, I’ve had 2D elements overlayed on top of the 3D world in Might is Right, and it looked pretty good to me.

But lately I’ve been wondering, what if I could apply rotation of these 2d elements based on camera transform. So I spent a bit of time and added support for that into the engine. Here’s what that looks like:

Honestly, I’m pretty happy.

Right now I compute rotation by taking 2 points in the world and transforming them both into view space, then taking the delta and using good old Math.atan2.

const angle = Math.atan2(up_ndcY - ndcY, up_ndcX - ndcX);

I keep thinking that there must be a better way to do that, to avoid all that extra math, plus the second point seems a bit wonky, I’m just taking the original world point + Vector(0,1,0).

Anyone got ideas?

1 Like

yes, why dont you just take 2D point at a fixed y below the screen, and rotate 2D items towards that? without any 3D voodoo at all? that is, assuming 3D camera does follow your character at the fixed distance

ha, that’s not a bad idea, but the camera is mostly free. Plus I wanted an engine solution, not something specific to a given camera setup. Though it is a bit hacky right now.

1 Like