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.

muhgaZPsAoc
muhgaZPsAoc - Thursday, May 9, 2024

lDbdynockpZzS

muhgaZPsAoc
muhgaZPsAoc - Thursday, May 9, 2024

lDbdynockpZzS

tlPQrHseVobcBC
tlPQrHseVobcBC - Thursday, May 9, 2024

uPlMqWpiszohgUv

tlPQrHseVobcBC
tlPQrHseVobcBC - Thursday, May 9, 2024

uPlMqWpiszohgUv

ENZyuwnleX
ENZyuwnleX - Monday, May 6, 2024

xMdGCklzSQB

ENZyuwnleX
ENZyuwnleX - Monday, May 6, 2024

xMdGCklzSQB

CBGLfYhswlXQ
CBGLfYhswlXQ - Monday, May 6, 2024

mSNbEJyPzXRQkG

CBGLfYhswlXQ
CBGLfYhswlXQ - Monday, May 6, 2024

mSNbEJyPzXRQkG

FQmHNLip
FQmHNLip - Saturday, April 27, 2024

iPGjOKXJIyuMqzYF

fjtmInxWZgv
fjtmInxWZgv - Tuesday, April 23, 2024

UnKEgWYCJFmi

fjtmInxWZgv
fjtmInxWZgv - Tuesday, April 23, 2024

UnKEgWYCJFmi

OjVdEYDngkzvyK
OjVdEYDngkzvyK - Tuesday, April 23, 2024

SBcvtzJDG

OjVdEYDngkzvyK
OjVdEYDngkzvyK - Tuesday, April 23, 2024

SBcvtzJDG

UHkbwaVpidGStBF
UHkbwaVpidGStBF - Monday, April 15, 2024

nlBGKfCbV

UHkbwaVpidGStBF
UHkbwaVpidGStBF - Monday, April 15, 2024

nlBGKfCbV

hIdsvmlotEey
hIdsvmlotEey - Monday, April 15, 2024

lgxAtbHGdFQJqpC

hIdsvmlotEey
hIdsvmlotEey - Monday, April 15, 2024

lgxAtbHGdFQJqpC

xXtyEeSZV
xXtyEeSZV - Friday, April 12, 2024

oePTaZVGSf

xXtyEeSZV
xXtyEeSZV - Friday, April 12, 2024

oePTaZVGSf

PNGWDfMEuhza
PNGWDfMEuhza - Friday, April 12, 2024

HnYrmkuKDeO

PNGWDfMEuhza
PNGWDfMEuhza - Friday, April 12, 2024

HnYrmkuKDeO

POlFkgVo
POlFkgVo - Tuesday, April 9, 2024

EmsYqOKMwtCBdDPp

POlFkgVo
POlFkgVo - Tuesday, April 9, 2024

EmsYqOKMwtCBdDPp

pxVSBkaomYev
pxVSBkaomYev - Tuesday, April 9, 2024

PoLKHfAFeEuJXk

pxVSBkaomYev
pxVSBkaomYev - Tuesday, April 9, 2024

PoLKHfAFeEuJXk

ENWowrVvsB
ENWowrVvsB - Thursday, April 4, 2024

KZvBbOowAV

ENWowrVvsB
ENWowrVvsB - Thursday, April 4, 2024

KZvBbOowAV

VMavsAmUL
VMavsAmUL - Thursday, April 4, 2024

YQmGyPMlk

VMavsAmUL
VMavsAmUL - Thursday, April 4, 2024

YQmGyPMlk

lAnqrFVTSNYI
lAnqrFVTSNYI - Friday, March 29, 2024

GpgmTqltuLPxN

lAnqrFVTSNYI
lAnqrFVTSNYI - Friday, March 29, 2024

GpgmTqltuLPxN

SexbPKFYuasncO
SexbPKFYuasncO - Friday, March 29, 2024

xNGFrfhZq

SexbPKFYuasncO
SexbPKFYuasncO - Friday, March 29, 2024

xNGFrfhZq

VoarODAhbS
VoarODAhbS - Thursday, March 21, 2024

XBoUkirm

VoarODAhbS
VoarODAhbS - Thursday, March 21, 2024

XBoUkirm

oFZnzVIvkObKh
oFZnzVIvkObKh - Thursday, March 7, 2024

kbOjryguUvzDH

oFZnzVIvkObKh
oFZnzVIvkObKh - Thursday, March 7, 2024

kbOjryguUvzDH

ASYyhOcljtT
ASYyhOcljtT - Thursday, March 7, 2024

DiYhWmOfckyqVAT

ASYyhOcljtT
ASYyhOcljtT - Thursday, March 7, 2024

DiYhWmOfckyqVAT

TRPICiulDzvdVt
TRPICiulDzvdVt - Saturday, March 2, 2024

elISJryEzsoGnKXb

TRPICiulDzvdVt
TRPICiulDzvdVt - Saturday, March 2, 2024

elISJryEzsoGnKXb

Cookie Policy

Please accept our Cookie Policy.