View Type Example Question

CurioShelf

New member
I created a fresh install of V3, unity version 2022.1.23f1, and am working through the documentation so I can grow an understanding of the changes.
When I got to the viewtype example for a static camera I receive an error.
1669557342231.png
I remember I had this example working before V3 release. Can someone assist with what has changed or needs to be updated?

Thank you for your help. I'm hoping to use it for a retro static camera.
 
Last edited:

Justin

Administrator
Staff member
Thanks for letting me know. The documentation needed to be updated - the CharacterRotation property changed to BaseCharacterRotation. I've updated the docs.
 

CurioShelf

New member
Thank you so much for responding on a Sunday.
Two more things.
1. Once I added the update I received another error about "m_CharacterTransform" not existing. I looked into another view and did not find any reference to m_CharacterTransform.Forward. However, I did find that you used m_Transform.Forward. I made the change and it appears to be working correctly. Is this correct? If not what should it be. (See code changes below)
2. Also, is it possible to stop the head from looking in the direction of the camera? Only way I could get it to work in the demo scene or custom scene was to create a character without Unity IK selected on creation. If the character has IK, I add the component Character IK and drag the Look at Head Weight to 0 nothing changes. Picture demonstrating what I don't want.
Thanks again for the support.
1669589613872.png

Code:
using UnityEngine;

using Opsive.UltimateCharacterController.Camera.ViewTypes;

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

    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 BaseCharacterRotation { get { return m_BaseCharacterRotation; } }
    public override float LookDirectionDistance { get { return 100; } }

    public override void ChangeViewType(bool activate, float pitch, float yaw, Quaternion baseCharacterRotation)
    {
        if (activate)
        {
            m_Pitch = pitch;
            m_Yaw = yaw;
            m_BaseCharacterRotation = baseCharacterRotation;
        }
    }

    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_Transform.forward;
    }
}
 
Last edited:

Justin

Administrator
Staff member
1. Once I added the update I received another error about "m_CharacterTransform" not existing. I looked into another view and did not find any reference to m_CharacterTransform.Forward. However, I did find that you used m_Transform.Forward. I made the change and it appears to be working correctly. Is this correct? If not what should it be. (See code changes below)
You should now use the rigidbody instead of transform. This page explains more:


2. Also, is it possible to stop the head from looking in the direction of the camera? Only way I could get it to work in the demo scene or custom scene was to create a character without Unity IK selected on creation. If the character has IK, I add the component Character IK and drag the Look at Head Weight to 0 nothing changes. Picture demonstrating what I don't want.
Setting the head/body weight is correct. I just tried this and it worked, though I did make some IK changes. That shouldn't have affected this though. Is that a new project?
 

CurioShelf

New member
It is a fresh project with only UCC installed.

Also to verify, in the static cam example in the documentation script I should not use m_CharacterTransform.forward or transform.forward? Ok will look into the link you posted.
 
Last edited:

Justin

Administrator
Staff member
It is a fresh project with only UCC installed.
Hmm, I'll try it out. It works in my development project and I'll be submitting an update this week but I didn't change anything which would have affected this.

Also to verify, in the static cam example in the documentation script I should not use m_CharacterTransform.forward or transform.forward? Ok will look into the link you posted.
Correct. You should now use the rigidbody: m_Rigidbody.rotation * Vector3.forward.
 
Top