Cinemachine and rotation

Wydlfire42

New member
Hello,

I had a previous thread here where I was using the Cinemachine Freelook camera for a 3rd person camera and having trouble getting my UCC character to walk straight. I ultimately resolved that by changing a setting on the camera that mostly fixed things enough for me.

But, fast forward a bit and I decided I wasn't happy with the way the Freelook camera "felt", and discovered that the advice I'd gotten to use it in the first place was dated. The current recommendation is to use a standard Cinemachine Virtual Camera with the "3rd Person Follow" setting. I followed the directions here:

The gist is that you create a Gameobject as a child to your character, have the camera follow that game object, and then have the controls rotate that object directly. It works really well, and my camera controls now feel exactly like I want them to.

Unfortunately, I've now returned to my original "I can't walk straight" problem with UCC. I *think* that UCC is looking at the Cinemachine camera, seeing that it's perfectly behind the object it's following, and then assuming that means the camera is exactly behind the character? And ideas on how I can address this?
 
I think this is what's happening, and I made an illustration that I hope will help explain.

Let's say the camera is pointing at the right side of the character at 90 degrees, so, on screen it looks like the character is facing right. You then press Up/Forward on the controller or keyboard or whatever. That causes UCC to want to rotate the character 90 degrees to their left so that they're facing into the screen. But, because the GO that the camera is following is a child of the character, it also gets rotated the same 90 degrees to the left and the camera follows. Which leads to a feedback loop of spinning.

So, I *think* what needs to happen, somehow is either the GO needs retain its same world space *rotation* when the character moves.. OR, it needs to be rotated in the opposite direction of the character the same number of degrees that the character is rotated until it's forward vector is the same as the character's, at which point it would 'stick'.

Does this make sense? How would you go about either of those things, or, is there a better option?

444EB6B8-0033-4DAB-BC9B-3A90BDA0EA35.jpeg
 
I do think that your explanation makes sense. Instead of following the child GameObject can you instead just use an offset from the character? This will then allow it to be independent of the character's rotation.
 
I do think that your explanation makes sense. Instead of following the child GameObject can you instead just use an offset from the character? This will then allow it to be independent of the character's rotation.
Something like that is one of the experiments I'm going to try.

Is there a callback or something I can hook into on UCC that will let me know when it's rotating the character and by how much?
 
I was able to solve it the way I wanted by making a:
private Quaternion lastKnownWorldRotation;

ivar, then in my Update() I start out with:

tranform.rotation = lastKnownWorldRotation;

and at the end of Update() after I've recalculated how the tracked GO should be rotated I save the result:
lastKnownWorldRotation = transform.rotation;

The effect is completely divorcing UCC's locomotion from being able to affect the camera rotation at all, which in my case feels perfect. But, I'm still curious if I wanted to have the camera gradually move behind the character when UCC moves them, is there a way to know when that happens other than obviously monitoring the character's rotation directly?
 
Top