So, I’ve been beating on this a few hours now, let’s see if one of you can tell me how I’m an idiot (at least in this context, we don’t have all day!)
I’m using the Starter Assets 3rd Person Controller in its out-of-the-box form. Relevantly, it creates a CineMachine brain and player follow camera, and assigns the cinemachine Follow target of the latter to a “PlayerCameraRoot” object that’s a child of the PlayerArmature.
My world is big, so whenever I get to some predefined limits, I snap the Player Armature (and everything else in the world) back into some known position closer to the origin:
Vector3 posDelta = new Vector3((float)deltaX, 0, (float)deltaZ);
trackedEntity.transform.position += posDelta;
That works great, except that the follow camera visibly zips over/through the terrain to return to its former position behind the Armature.
The Internet–which would never lie to me–tells me that I need to do some form of:
CinemachineCore.Instance.GetVirtualCamera(i).OnTargetObjectWarped(target, delta);
“Delta” is that posDelta from above, but “target” is a challenge: if I use the armature (“trackedEntity” in this case), nothing happens, probably because none of the virtual cameras are actually tracking the armature. If I use the PlayerCameraRoot, it doesn’t work either, because its Transform actually hasn’t changed (the player camera root didn’t move, its parent did).
If I change the follow camera to look at the Armature itself, the origin float DOES work, but it breaks the 3rd Person Controller in myriad fascinating and frustrating ways: you stop being able to look with the mouse, or the mouse position sets the orientation in all three axis of the armature itself (look down and you’ll lean forward, look back and you’ll fall in place).
I’ve tried updating the 3PC code to work with Cinemachine following the armature rather than the camera root; but enough of the code depends on that specific arrangement that I’m basically re-writing move/look myself. The bugs have been interesting: at one point I summoned an Elder Horror, but it didn’t find my brain worth eating. I’m probably going to have to go down this route eventually, anyway, but it’s not what I’d prefer to be spending my time on at the moment.
What I think really need is a way to tell the Cinemachine follow camera “Hey, forget everything you know about what you’re following, and just re-position youself back in the initial relative state and start over.” But I’ve had no luck finding that, either. I’ve tried unsetting the Follow target and then doing ForceCameraPosition() on the vcam, and then re-setting the Follow target, but it didn’t have any visible effect (maybe I need to do the re-set of the Follow target on a subsequent frame?).
If anyone can give me the presumably simple trick I’m missing here, I promise not to tell the Elder Horror how good your brain is.