Hello, I’m trying to set up a feature where a camera will instantly jump to behind the player, like a lot of 3rd person games do when you press the right control stick, for example.
I came up with something that basically works, but it doesn’t provide for a lot of control. Basically the goal is to reposition the camera so that its transform.forward, projected onto the ground plane, is the same as the player’s transform.forward, also projected onto the ground plane.
(You can see this work when the camera rotates but the mouse is not moving)
The difficulty I’m having is that it seems that the only way I’ve found to swing the camera around is by overriding CinemachineCore.AxisInputDelegate. This works, but the output is not predictable - or at least I don’t know how to predict it.
What I currently do is, get the signed angle between the camera and the desired position, which determines if I need to swing left or right. Then I override the axis input with my custom function. Then I start a coroutine, which tests whether the camera is inside a tolerance, or if the dot product of camera.transform.forward and player.transform.forward is less than the previous frame (which means we’ve overshot) or if it’s greater than a tolerance value, say 0.95f. Then I return the axis input function to its original reference.
The custom input function basically just multiplies a speed value times the sign of the original angle (left or right). It ignores the Y axis.
Like I said, this does work, but some problems with this:
-
I can’t set a duration. Normally I would let the user set a duration, but because I am rotating some amount that I don’t seem to be able to control per frame, I don’t know how long it’s going to take. I can set a speed multiplier, but this is still not optimal.
-
The motion is robotic. I have introduced an animation curve, but the problem is determining the input value of the curve because I don’t have the total duration. What I’m doing instead is using the progress from the starting dot product to
1f, but this makes it hard to control because small values will cause very little change between frames, and curving sections are more abrupt. -
Eventually I would like to override the Y axis too, to get the camera to a specified distance behind the player, or at least a specified distance on the curve that bridges the three rigs. However, because the method starts and stops based on guessing and checking the X value, I can’t couple the end time of the Y adjustment to the end time of the X adjustment. In other words, maybe I’ll be at the right angle well before or well after I’m at the right distance.
-
Its unclear how the output value is consumed. I haven’t been able to determine what value corresponds to one degree of movement, for example, and I think it is not intended to enable this - probably for smoothing purposes.
Any thoughts on how to remedy this? Any possibility this functionality will be introduced into the controller? Or am I missing some silver bullet?

