What is the best way to control CM position and the Recenter Offset?

I’ve a project that I’m working on, where I have a 3rd person character movement, for the camera I’m using a CM Virtual Machine, my problem is actually that I want the both Recentering functions of Virtual Machine camera (X and Y recentering) to lead the camera to the position behind the characters back, right now it’s at a global position, related to the world.

In a brief, my problem is the camera recentering to a fixed world position and the character be facing a direction and the camera is not on the character default back view position, on horizontal (X Recentering). I’ve tried two scripts which I’ll let their respective methods of my tries below, they didn’t work.

So what is the bast way to change the default position the camera should recenter to related to the characters 3rd person back instead of the world related fixed position?

Method of try #1:

private void PositionCameraBehindCharacter()
    {
        if (transposer == null) return;

        Vector3 relativePosition = target.InverseTransformPoint(doorFrameCamera.transform.position);

        float targetDistance = Mathf.Lerp(relativePosition.z, -distanceBehindCharacter, Time.deltaTime * 5.0f);
        Vector3 targetOffset = Vector3.Lerp(transposer.m_FollowOffset, new Vector3(0, cameraOffset.y, targetDistance), Time.deltaTime * 5.0f);

        transposer.m_FollowOffset = targetOffset;
    }

Method of try #2:

private void Update()
    {
        // Get the default recentering position for the camera
        Vector3 defaultRecenterPosition = _virtualCamera.State.FinalPosition;

        // Calculate the target position for the camera with an offset behind the character
        Vector3 targetPosition = _target.position - _target.forward * _distance + Vector3.up * _height - _target.right * _recenterOffset;

        // Smoothly move the camera towards the target position
        transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * _damping);

        // Rotate the camera to look at the target
        transform.LookAt(_target);

        // Set the default recentering position to the offset position behind the character
        _composer.m_TrackedObjectOffset = Vector3.right * _recenterOffset;
    }

Can you show a picture of your VirtualCamera inspector?

My apologies, attached below are the respective CineMachine camera prints from the inspector, I also attached a desired point of view I want the camera to always back when recentenring (Vertical and Horizontal) regardless the character direction.




8913052--1220587--CM_4.PNG
8913052--1220590--Desired_Recenter.PNG

Try this:

Can’t believe it was this simple! It solved, thank you very much!

1 Like