Hello,
I am trying to change the follow offset of the camera via code based on whether i am in portrait or landscape.
If anyone knows how to do this would greatly appreciated.
Please advise.
Many thanks
Daniel
Hello,
I am trying to change the follow offset of the camera via code based on whether i am in portrait or landscape.
If anyone knows how to do this would greatly appreciated.
Please advise.
Many thanks
Daniel
Assuming that you are using an ordinary Transposer:
CinemachineVirtualCamera vcam = ...;
var transposer = vcam.GetCinemachineComponent<CinemachineTransposer>();
transposer.m_FollowOffset = bla;
If you’re using a different thing in the Body section, replace “CinemachineTransposer” with the appropriate class.
Perfect!
Thank you
Best
Daniel
Hi, I’m trying to change the offset of the aiming section via code but couldn’t get it to work. The value did change when I printed it out but the camera’s offset didn’t change at all?. Do you have any idea why?
@duyanhpham235 Please show your code
Hi, Thanks for answering so quickly. I figured that out. Turns out, it didn’t work because I get the trackedObjectOffset component on Awake() and made changes to that later on. I’m not sure why it doesn’t work that way though?
More importantly, I’m trying to achieve the following behavior:
I currently have 2 cameras, 1 freelook cam for third-person view on my character, 1 virtual cam for some special situations.
Normally, players will be using the freelook camera, but when those special situations do happen, I want to switch to virtual cam with the camera angle stay exactly the same as before switching. How can I achieve that?
For the virtual cam settings, I want it to only follow the character’s position and not rotation. And no matter how crazy the character is rotating, the camera angle stays the same. I attached my current setting below.
I’ll try to record some video to show you exactly what I’m trying to achieve if these descriptions are not clear enough.
It doesn’t work the second way because you’re just storing difference in a local variable. You want to set it in the Composer component.
It’s good for performance to get the vcam components in Start() instead of Update(), so you should fix that. Store the component in your class, and do _composer.m_TrackedObjectOffset = difference in Update().
When you switch, you’ll have to set the incoming vcam’s offset to be outgoingVcamPos - targetPos, and use WorldSpace binding mode in the incoming vcam.
Not sure what you meant by setting it in the Composer component. Can you rewrite it in the proper way please?
CinemachineComposer _composer;
void Start()
{
_composer = vcam.GetCinemachineComponent<CinemachineComposer>();
}
void Update()
{
_composer.m_TrackedObjectOffset = difference;
}
I noticed a few things:
Setting the virtual camera to World Space and change only followOffset (and not trackedOffset) to (freelookPos - targetPos) gives me almost the exact same angle but not quite. It also doesn’t behave like “Simple Follow with World Up” which is what I’m looking for.
Changing followOffset to (freelookPos - targetPos) with “Simple Follow with World Up” doesn’ give me the right angle. Same result when changing both followOffset and trackedOffset to (freelookPos - targetPos).
(UPDATE)
Thanks for the upload, but I don’t really understand what I’m looking at, or how it was before, or exactly what you want.
My current understanding is this:
Is that right? If so, then you need to
Set the vcam’s Transposer binding mode to WorldSpace,
Set the Aim to Composer, trackedObjectOffset = same thing as FreeLook’s trackedObjectOffset
Set brain.defaultBlend = cut, or have a custom blend setting for vcam which is cut
When the player is hit:
Set vcam.GetCinemachineComponent.m_FollowOffset to Camera.Main.transform.position - player.transform.position
Set vcam.PreviousStateIsValid=false
Activate vcam
Still unclear: What should happen when FreeLook is re-enabled?
Hey Gregoryl, sorry for late response. You understood it correctly. It’s working as intended right now but I do have 1 more question. When the recoil camera is activated, we want it to zoom out as much as needed so that it fits both the person who gets hit and the one who shoot. How can I do that?
Thank you
You would need to scale the length of m_FollowOffset, taking into account the FOV, so that the frustum includes both targets. There’s code in CinemachineFollowZoom that makes that calculation - have a look at it. Sorry I can’t be more precise than that, I’m away and not on a machine that has code on it
I simply want to offset the camera’s final X and Z position so that the camera moves a bit towards the mouse’s cursor.
My camera is angled @ 55 degrees on my player and it uses the following component (FramingTransposer):
I used the m_TrackedObjectOffset but it only works when my character is facing forward. Apparently TrackedObjectOffset takes into consideration the orientation of the Transform it looks at.
What can I do to displace the camera’s position after it being moved by the Cinemachine Virtual Cam? (Like you would do with a normal gameobject using transform.position)
You can’t displace the camera, because the vcam will move it right back to where you said to put it. You have to tell the vcam to put it where you want it. With the FramingTransposer, you can dynamically adjust the ScreenX and ScreenY parameters. Alternatively, you can use an invisible game object as your actual target, and have a script that positions that in relation to the player.