Forum rules - please read before posting.

Help Needed on Parenting a Static Cam

edited May 2022 in Technical Q&A

Good morning,

I am using the integration between UCC and Adventure Creator and followed all of the steps.
After some work I decided to use the static cam set up from UCC since it allows the movement I want (W moves the character to the top of the screen S to the bottom etc).
However, for it to work perfectly the static camera needs to match the transforms of the AC camera as it switches between positions. So my first thought was I'll parent them together and it should work.
Not really.
When I hit play both cameras go to the starting navcamera I have set.
When my player enters a trigger the ACCamera switches to the second Nav Cam as it should. However the UCC camera stays at the starting position not following. So my view changes as I want but the character controls are no longer correct, as the player is still acting based off of the original position.

Short video showing the issue. Sorry my voice is very quiet.
If you need a louder version I can post one later today.

Also here is the code for the static camera from UCC.

using UnityEngine;
using Opsive.UltimateCharacterController.Camera.ViewTypes;

public class StaticCam: ViewType
{
private float m_Pitch;
private float m_Yaw;
private Quaternion m_CharacterRotation;

public override bool FirstPersonPerspective { get { return false; } }
public override float Pitch { get { return m_Pitch; } }
public override float Yaw { get { return m_Yaw; } }
public override Quaternion CharacterRotation { get { return m_CharacterRotation; } }
public override float LookDirectionDistance { get { return 100; } }

public override void ChangeViewType(bool activate, float pitch, float yaw, Quaternion characterRotation)
{
    if (activate)
    {
        m_Pitch = pitch;
        m_Yaw = yaw;
       m_CharacterRotation = characterRotation;
    }
}
public override Quaternion Rotate(float horizontalMovement, float verticalMovement, bool immediateUpdate)
{
   return m_Transform.rotation;
}
public override Vector3 Move(bool immediateUpdate)
{
    return m_Transform.position;
}
public override Vector3 LookDirection(Vector3 lookPosition, bool characterLookDirection, int layerMask, bool useRecoil, bool includeMovementSpread)
{
    return m_CharacterTransform.forward;
}

}

Thanks in advance for any help or direction.

Comments

  • Did a second video of what happens if I attach the AC MainCamera to the UCC static camera. The camera does react in the way I expect it to except it doesn't pick up on hotspots.

  • Welcome to the commuity, @CurioShelf.

    With the approach in the first video, you won't want to attach a "Basic Camera" component to your UCC Camera nor assign it as the default in the Scene Manager. The UCC Camera should remain independent of AC, component-wise, since it's already a child of MainCamera.

    Because of this parent/child relationship, the UCC Camera should adopt the position and rotation of the AC MainCamera automatically. That it's not copying the rotation suggests that it's being overridden by a script - potentially the one you've shared.

    What you'll want is to make sure that the rotation of the UCC Camera and AC MainCamera matches - it may be a case of updating the Rotate function to something like:

    return m_Transform.parent.rotation;
    

    That'll be a question for UCC, however.

    With the approach in the second video, you have both asset's cameras attached to the same object - with both attempting to control the object's rotation. I'd guess that it's a case of the rotation being what UCC "wants" it to be, then AC performing raycasting for Hotspots (in the wrong direction), and then AC updating the rotation for the MainCamera before rendering the frame.

    What you'd want to do here is make sure that the UCC Camera is not setting its own rotation. If you were to unset your AC GameCameras so that the AC MainCamera was not "attached" to anything, you'd want to be able to freely move and rotate the MainCamera object in the Scene window without UCC locking it in place. This might be a case of tweaking the script - but UCC's developer would be better equipped to answer how exactly.

  • edited May 2022

    Thank you so much! It was, as you said, setting the static cam (UCC Camera) to return the parent rotation and position and making sure that it didn't have basic camera attached. Works like a charm and performs exactly as I wanted.

    `using UnityEngine;
    using Opsive.UltimateCharacterController.Camera.ViewTypes;

    public class StaticCam: ViewType
    {
    private float m_Pitch;
    private float m_Yaw;
    private Quaternion m_CharacterRotation;

    public override bool FirstPersonPerspective { get { return false; } }
    public override float Pitch { get { return m_Pitch; } }
    public override float Yaw { get { return m_Yaw; } }
    public override Quaternion CharacterRotation { get { return m_CharacterRotation; } }
    public override float LookDirectionDistance { get { return 100; } }
    
    
    
    public override void ChangeViewType(bool activate, float pitch, float yaw, Quaternion characterRotation)
    {
    
        if (activate)
        {
            m_Pitch = pitch;
            m_Yaw = yaw;
           m_CharacterRotation = characterRotation;
        }
    }
    
    
    public override Quaternion Rotate(float horizontalMovement, float verticalMovement, bool immediateUpdate)
    {
       return m_Transform.parent.rotation;
    }
    
    public override Vector3 Move(bool immediateUpdate)
    {
        return m_Transform.parent.position;
    }
    
    public override Vector3 LookDirection(Vector3 lookPosition, bool characterLookDirection, int layerMask, bool useRecoil, bool includeMovementSpread)
    {
        return m_CharacterTransform.forward;
    }
    

    }`

    For anyone wanting to do a similar integration.

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.