Forum rules - please read before posting.

First Person Zoom Camera

edited December 2023 in Technical Q&A

I'm using a zoom function, that should zoom the Camera when the right click is held, and return to it's original FOV when released.

It is a First Person Player and i'm also using Cinemachine -
seperate Cinemachine Brain like in the Manual on it's own Game Object, and a Cinemachine Virtual Camera is attached to the Main Camera.

private void Update()
{
if (Input.GetMouseButtonDown(1)) // Right mouse button pressed
{
changeCameraPOV.fieldOfView = Mathf.Lerp(changeCameraPOV.fieldOfView, zoomedFieldOfView, Time.deltaTime * >zoomSpeed);
}else
{
changeCameraPOV.fieldOfView = Mathf.Lerp(changeCameraPOV.fieldOfView, originalFieldOfView, Time.deltaTime * >zoomSpeed);
}

or simpler:

PlayerCameraPOV.fieldOfView = (originalFieldOfView / 2);

but even if i add all the Cameras that i have, where i don't know which one is fighting with each other, it doesn't work.

Something somewhere forces it to be a FOV of 60, instead of the one i specified. Even if i add all of them like this:

PlayerCameraPOV.fieldOfView = (originalFieldOfView / 2);
MainCameraPOV.fieldOfView = (originalFieldOfView / 2);
virtualCamera.m_Lens.FieldOfView = (originalFieldOfView / 2);

What could i be missing?

Unity: 2022.3.14f1
AC: 1.79.2

Comments

  • Despite the use of Cinemachine, are you still relying on AC's First Person Camera on your Player? If so, that's the one that will be the one that needs updating.

    Otherwise, I'll need to see your various cameras to understand how things are set up.

    I'm not sure where you're seeing the advice for attaching a VCam to AC's MainCamera, though - can you point to the Manual page number? If you're looking to mix and match AC and CM cams, it generally should be the other way around - i.e. attaching AC's Basic Camera to the CM Brain.

  • edited December 2023

    You are right, i've remade it in a Test Project, because i had setup something wrong, in order to achieve this behaviour.

    I want the Cinemachine Camera Composer to work according to the Settings, but that only works, if i enable the Camera Component on the Player - and in doing that i break all the functions related to the AC Main Camera.

    I'm not sure if what i'm aiming for is possible, without breaking AC Cams in the process.

    Here in Picture form:
    https://i.ibb.co/T8JXsq5/1-Hierarchy.png
    https://i.ibb.co/1XfcfTg/2-AC-Main-Camera.png
    https://i.ibb.co/cTBT6n7/3-Cinemachine-Brain.png
    https://i.ibb.co/2W110GK/4-Player-Camera.png

    And i've also recorded a video of the Behaviour that i'm aiming for:
    https://streamable.com/e/6rfpdi?

    //Additionally would it be possible to have the Cursor follow this Object aswell, instead of being centered?

  • edited December 2023

    You can ignore the post before, i don't know what the heck changed.
    But after trying around a bit more, i have managed to get it working the way i want by adding the VCam to the Main Camera, now everything works fine, including zooming.

    Would it be safe to use it that way?

    ">

    The remaining question is: Would it be possible for the cursor to "follow" or point to the place that the pointer is in the cinemachine deadzone, instead of being center all the time (which would probably be fine aswell, just a tiny bit more finicky when clicking hotspots).

  • Would it be safe to use it that way?

    So long as you rely on this camera setup for gameplay, yes. Hotspot interactivity etc refers to AC's MainCamera, so you'll get issues with clicks not registering properly if/when the game isn't viewed through the MainCamera.

    The AC / Cinemachine workflow is flexible, and there are a few ways to set it up depending on needs. I should mention that AC has a Cinemachine integration package over on the Downloads page with a couple of examples - you may like to check this out in a fresh project.

    Would it be possible for the cursor to "follow" or point to the place that the pointer is in the cinemachine deadzone

    I'm not sure how you'd determine the deadzone "position", but you can control the AC cursor position using the InputMousePositionDelegate when unlocked, and the OverrideLockedCursorPosition function when locked.

    Is it the locked or unlocked cursor you're looking to affect?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.