Camera movement problems when rolling the character around the forward axis.

OuterGazer

New member
Hello everyone!

I am trying to implement a Space Movement ability that allows the character to rotate freely in all directions and where the character is always facing forward, rotating with mouse movement.

My main problem is the camera movement not keeping itself relative to the local axis.
For an example, if in the Combat ViewType in Third Person you establish the Pitch limit to -90 and 90 (basically allowing for limitless pitch), as you turn completely around the X movement is inverted.
In the Combat version of the First Person this is solved in the overridden Rotate method by checking the pitch value and multiplying horizontalMovement by -1.

Now comes rolling the character. I acknowledge that I may not be doing things the proper way as I'm still new to the UCC and uncertain on how some things may work.

In the ability script itself, in an overridden UpdateRotation() I check for the rolling input and then apply the rotation to m_CharacterLocomotion.DesiredRotation after some lerping. However, the camera here doesn't follow the character and if I set AlignToUpDirection to true when starting the ability it does align, but rotates the character endlessly, and stronger the greater I move the mouse.

Another alternative I tried was, in this same method, grab a reference to the camera and set its rotation the same as the previous one. I know for sure this isn't how something like this must be done because, even though now the camera's up aligns properly with the character, the mouse movement doesn't "update", so to say, and keeps moving in the original axis before any roll was applied, causing a similar problem to the pitch example mentioned earlier.

After some digging, I have seen that maybe I need to override the Move() method from ThirdPerson (ViewType)? I've been a couple of days banging my head against the wall and I would highly appreciate if someone could point me in the right direction.

Cheers!
 
I think that you are getting close. I would subclass the AlignUpDirection base class and provide your own Update method which calls Rotate(targetNormal). This will ensure everything is setup correctly in terms of aligning to a new normal. In some sense your ability will be really similar to AlignToGround except instead of orienting according to the ground normal you instead orient to your own vector.

The AlignUpDirection will take care of setting the AlignToUpDirection field for you. You should not need to do anything new for the ViewType - this uses the AlignToUpDirection field and align based on the rotation limits.
 
Thanks for the response. I think I almost got it, but not quite.
I followed your advice and subclassed AlignUpDirection. However, if I let it run every frame, rolling or just moving the mouse causes a continuous rotation. If I put a check in place to only let Rotate(targetNormal) run exclusively when I press the rolling buttons it avoids this continuous rotation but then the camera up doesn't align with the character's up even if I put the AlignSmoothing to 0, it stays at an offset.
 
Last edited:
You should call Rotate every frame in order to ensure it is the correct target rotation. If it's the same vector then there won't be any new rotation.

With that said, is your target vector correct when the mouse moves?
 
Back
Top