Camera Movement with joystick not working with Rewired and Cinemachine?

Sangemdoko

Moderator
Staff member
Hi,

I've been testing out my game in the editor using my mouse and keyboard for about two-three weeks now. And I recently thought that I should also make sure things work with a controller.

And turns out my Camera does not move when I use my right joystick, it works perfectly fine when I use the Mouse though. from what I can tell all the other inputs work just fine.

So here is how I got my things set up:

1548516926781.png

1548516956388.png

1548516991814.png

I don't have anything set up to differentiate using a controller or the mouse and keyboard, at least I haven't added anything to the default states.

Could it be that the Mouse X and Y input get reset by the mouse before the Cinemachine Camera gets to move?
Maybe I haven't it up correctly.


Also on a side note, probably isn't related but, when I load up my scene for the first time my character is always running. When I change scenes, or when I load the scene from the title screen, I need to press shift to run. I have no idea why. From what I can tell my character controller is setup to run only when shift is hold down. Not too much of a problem since I plan to have the character always run, I'm just curious.

Thank you for your time,
Santiago
 
The Mouse X and Y input are retrieved within PlayerInput.UpdateLookVector. If you add some debugging calls to this method you should be able to see if it's an issue related to how Rewired is setup or something else.

Also on a side note, probably isn't related but, when I load up my scene for the first time my character is always running. When I change scenes, or when I load the scene from the title screen, I need to press shift to run. I have no idea why. From what I can tell my character controller is setup to run only when shift is hold down. Not too much of a problem since I plan to have the character always run, I'm just curious.
Is the Speed Change ability active? You can check when it can run by placing a breakpoint within SpeedChange.CanStartAbility.
 
Hi Justin,

So I can confirm the the problem is not related to rewired. m_RawLookVector.x and y from the base calsse PlayerInput do get updated while I move the joystick around.

Since it is pretty sure that cinemachine or my viewtype is the problem I removed the Input Axis Name from the Axis Control on my Cinemachine Free Look Camera. And now whether I move the mouse or the joystick the camera does not move. To my understanding, the ViewType should be updating the camera Look direction. Am I wrong?

Here is how I got my cinemachine camera set up:
1548579704301.png
I attached the Cinemachine Spring Extension to it. And I made sure the View Type does find it.

Then on the camera I got my View Type set up as such (It uses the Third Person Cinemachine as base class):
1548579820816.png
Of course, I tested with the Third Person Cinemachine ViewType and I get the same behaviour.


I tried to figure out the problem myself, and I realised that the "Rotate" function in the Cinemachine ViewType does not use the horizontalMovement and verticalMovement parameters to update the camera spring extension:

C#:
 public override Quaternion Rotate(float horizontalMovement, float verticalMovement, bool immediateUpdate)
        {
            // The up direction should always match.
            m_WorldUpOverride.up = m_CharacterLocomotion.Up;

            if (m_SpringExtension != null) {
                
                var orientationCorrection = Quaternion.identity;

                // If aim assist has a target then the camera should look in the specified direction.
                if (m_AimAssist != null) {
                    m_AimAssist.UpdateBreakForce(Mathf.Abs(horizontalMovement) + Mathf.Abs(verticalMovement));
                    if (m_AimAssist.HasTarget()) {
                        var rotation = m_Brain.CurrentCameraState.FinalOrientation;
                        var assistRotation = rotation * MathUtility.InverseTransformQuaternion(rotation, m_AimAssist.TargetRotation(rotation));
                        orientationCorrection *= assistRotation;
                    }
                }

                orientationCorrection *= Quaternion.Euler(m_RotationSpring.Value) * Quaternion.Euler(m_SecondaryRotationSpring.Value);
                m_SpringExtension.OrientationCorrection = orientationCorrection;
                
            }

            // Cinemachine manages the camera's orientation - don't change it.
            return m_Brain.CurrentCameraState.FinalOrientation;
        }

I looked at the Adventure View Type and that does use the parameters:

C#:
public override Quaternion Rotate(float horizontalMovement, float verticalMovement, bool immediatePosition)
        {
            // Update the rotation.
            m_Yaw += horizontalMovement;

            // Set limits on the yaw.
            if (Mathf.Abs(m_MinYawLimit - m_MaxYawLimit) < 360) {
                // Determine the new rotation with the updated yaw.
                var targetRotation = MathUtility.TransformQuaternion(m_CharacterRotation, Quaternion.Euler(m_Pitch, m_Yaw, 0));
                var diff = MathUtility.InverseTransformQuaternion(Quaternion.LookRotation(Vector3.forward, m_CharacterLocomotion.Up), targetRotation * Quaternion.Inverse(m_CharacterTransform.rotation));
                // The rotation shouldn't extend beyond the min and max yaw limit.
                var clampedAngle = MathUtility.ClampInnerAngle(diff.eulerAngles.y);
                var clampedYaw = Mathf.Clamp(clampedAngle, m_MinYawLimit, m_MaxYawLimit);
                m_Yaw += Mathf.Lerp(0, (clampedYaw - clampedAngle), m_YawLimitLerpSpeed);
            }

            // Return the rotation.
            return base.Rotate(horizontalMovement, verticalMovement, immediatePosition);
        }

I tried adding this at the top of the Rotate Script:

C#:
if(m_FreeLook != null)
{
    m_FreeLook.m_XAxis.Value = horizontalMovement;
    m_FreeLook.m_YAxis.Value = verticalMovement;
}

It makes the camera react to the joystick and mouse but it snaps back behind the character because of the rest of the code. Let me know how I should fix this. Maybe I'm the one that did not set things properly and the code has nothing to do with it.


By the way for the run issue, there is something really weird. The SpeedChange ability is Active whenever I move (press one of the arrow keys). But when the scene changes the character starts to walk. But now if I click anywhere outside the Game window, and click back, he starts running again. I have no idea why that is.

Thank you for your help
 
Ahh, that reminds me. The Cinemachine ViewType doesn't actually provide any input to Cinemachine. Cinemachine handles input on its own so does Rewired work with Cinemachine? This probably needs to be an independent integration. All that the ViewType is doing is telling the camera controller Cinemachine's current location and adding any spring forces.
 
It is good to know it wasn't a bug then.

I found a solution that worked for me:

I wrote this in my View Type which inherits the Cinemachine view type:

C#:
public override Quaternion Rotate(float horizontalMovement, float verticalMovement, bool immediateUpdate)
        {
            if (m_FreeLook)
            {
                m_FreeLook.m_XAxis.m_InputAxisValue = horizontalMovement;
                m_FreeLook.m_YAxis.m_InputAxisValue = verticalMovement;
            }
            

            return base.Rotate(horizontalMovement, verticalMovement, immediateUpdate);
        }

I did need to change the Cinemachine view type protection level variable: "protected CinemachineFreeLook m_FreeLook;"

it would be nice if you made all these variables as protected:


C#:
private UnityEngine.Camera m_Camera;
private CinemachineBrain m_Brain;
private Transform m_CrosshairsTransform;
private AimAssist m_AimAssist;
private Transform m_WorldUpOverride;
protected CinemachineFreeLook m_FreeLook; //changed this
private CinemachineSpringExtension m_SpringExtension;

although it is not that hard for me to make a copy of the script of change it whenever there is an update
 
Top