DOTS-TPC Story Time

Hey everyone!

I've made a post about my new release of a Third Person Camera for DOTS.
Also check out the WebGL demo and Documentation!

But here I want to give you a bit more of a dev story time of something that never really happened to me during programming before.

When Entities first came out I always knew I want to port my Third Person Camera system to DOTS.
I held off for 2 reasons. One was that Entities has to hit 1.0 and the other that I want to improve my previous camera in every capacity. Over the years some pain points, mostly regarding to authoring cropped up and the other was that I wanted to improve on the Follow mechanic. If you have been following the Souls games, they made some sneaky but great changes to how the camera behaves and it wasn't trivial to mimic that. I thought a LOT about it.

Usually programming is thinking about a problem and executing a logical sequence but the camera always felt more like an art form than a very technical sequence of steps with how rigid it is and how unknown player movement and the environment is. To keep this short, crazy things can happen and we all know bad camera systems. Clipping, jitter or erratic movement, the list goes on.
My MonoBehaviour Third Person Camera was very stable but it also has a very crude follow mode. It just aligns to the forward vector of the target. Okay for some games but for SoulsLike or adventure games it's not great.

So what did I want anyway?
It is actually simple to describe, when the target moves around and is still in view space the camera should only rotate in place.
Piece of paper, graphs, let's do this! This is easy!
Calculate this vector, apply this rotation, mhm, aha! Test it.
Total failure! Ok, back to the drawing board. Fail! Rinse and repeat.
Why is this not working! It is so simple but no matter what I do the camera will not stay in place accurately or have another issue, like sliding up or down when the camera is at an angle and the target is moving towards the camera.

I'm getting frustrated and let months pass by to try again. Doubts crop up. Is it even worth it? I've wasted so many hours on a feature no one even asked about.

Until one day, when I used the wrong vector for calculating the temporary forward vector and tested it. It worked perfectly!
I didn't even catch my error at first. Only after staring at the thing, why it works now, it hit me. I made a mistake and it solved my problem. A true Bob Ross happy accident!

It was so simple, like it should be, and I just had to use it the vectors the other way around.

        // very peculiar and important calculation of the forward, the targetPos is the new one, the camera pos is an old one
// that way we can calculate an angle that the camera stays in place
// we also use DesiredPosition because that's more stable than just PrevPosition
var tmpForward = math.normalizesafe(targetPosWithOffset - controllerState.DesiredPosition);

Before that and before other elaborate tries, I used the old target position and the new camera position but that wasn't really working out. The order and interpolation was screwing me over, time and time again without even realizing that the problem is not the logic of the calculation but somewhere else.

After solving that I got motivated enough to pack everything up as good as I can and release it to the world.
Of course, more problem occurred but none too severe to figure out.

I hope my little story was somewhat entertaining. :) Don't give up on your problems, sometimes it can take days, months or even longer but eventually it will work out even when it needs an happy accident. 

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.

gAtHfpOVJYRZx - Thursday, November 30, 2023


vOxSeqniHc - Thursday, November 30, 2023


BDfmWPSbyLicHl - Thursday, November 30, 2023


GANzFRpw - Thursday, November 30, 2023


jSXIGxVN - Wednesday, November 22, 2023


JOtDbcidl - Wednesday, November 22, 2023


Cookie Policy

Please accept our Cookie Policy.