i have a pretty good 3rd person camera setup with cinemach and the orbits setting are like this
i have aim on RMB and following a tutorial on the tube, i added an AimCamera script to the CM camera and in the code it does this
public class CameraAim : CinemachineExtension
{
public Vector3 Offset;
protected override void PostPipelineStageCallback(CinemachineVirtualCameraBase vcam, CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
{
if(stage == CinemachineCore.Stage.Aim)
{
state.PositionCorrection += state.FinalOrientation * Offset;
}
}
}
Offset is .5,0,2 so it places the camera behind and a bit to the right of the player, standard stuff
in the middle rig position, all is well but when i move up and down with the mouse, the camera lose sight of the player which i don’t like
so while the game was running i changed the top and bottom orbit to same as middle and it does what i want
so can change that in script? or am i doing it wrong? thanks
Yes you can change it in script. See CinemachineFreeLook.m_Orbits
.
thanks, i kinda got it with this code
using Cinemachine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraAim : CinemachineExtension
{
public Vector3 Offset;
protected override void PostPipelineStageCallback(CinemachineVirtualCameraBase vcam, CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
{
if (stage == CinemachineCore.Stage.Aim)
{
Debug.Log("PostPipelineStageCallback Aim");
state.PositionCorrection += state.FinalOrientation * Offset;
Cinemachine.CinemachineFreeLook flscript = GetComponent<CinemachineFreeLook>();
CinemachineFreeLook.Orbit[] florbits = flscript.m_Orbits;
// copy middle rig to top and bottom rigs
florbits[0].m_Radius = florbits[1].m_Radius;
florbits[2].m_Radius = florbits[1].m_Radius;
}
/*else
{
Debug.Log("PostPipelineStageCallback !Aim");
// revert to aim standard orbits
florbits[0].m_Radius = 1.75f;
florbits[2].m_Radius = 1.3f;
}*/
}
}
only problem is i don’t know where to revert to the none aim settings one i exit the PostPipelineStageCallback script
you can see i tried to do it in an else bu that doesn’t work obviously
any ideas? maybe in some other part of my main character script when i detect right mouse up
I don’t really understand what you’re trying to do. Can you describe a little more carefully the game conditions that would make you want to change the orbit dynamically, and then what conditions would make you want to change it back?
The normal approach would be to use 2 FreeLooks, each with different orbit settings, and blend back and forth between them when the change is required.