I have tried everything I can find that looks even remotely related, but I cannot find a way to change the axis of rotation of the camera. It seems like there must be some obvious way but I am stumped.
My first thought was to change the orientation of the camera attached to the player, but the functions I have found change where the camera is looking.
I tried changing the rotation of the controller, but it does not change how the view rotates when looking left/right.
I have also tried changing the orientation of the player capsule and of the character, but again, no effect.
Below are GIFs of what I am talking about. The first one is what happens when moving the mouse left/right in a hallway with a level floor:
The second is what happens when the mouse is moved left/right in a hallway that slopes upward forty degrees:
What I am trying to do is make it so that looking left/right in the sloped hallway is identical to doing it in the flat hallway.
Any ideas? I am hoping it is something obvious that I have missed.
Well theres only one kind of camera called camera component, maybe camera is somewhat attached to root component with some relative location and rotation and when you rotate root component camera it behave diffrenrly. Try setting camera component as root component
Thanks for the suggestion and taking the time to answer.
I tried your suggestion of setting the camera component to be the root component and attaching the capsule to it, but doing so removes the ability to move.
Any other thoughts? I am nearly to the point of seeing if standing on my head will help, so anything short of that is going to be worth a try.
It seems that the issue that you’re experiencing could be caused by multiple things. First of all it could be the code that is being used to turn the camera. If you are using the standard FPS camera, just like the one that is in the scene by default in the editor’s First Person Shooter example, this is not the problem. The other problem would be the hierarchy of the components for your character. Looking at the First Person Shooter example, the character’s hierarchy goes as follows
This means that the FirstPersonCameraComponent is a child of the CapsuleComponent. If your FirstPersonCameraComponent is offset from its parent, things can look weird when its parent is turning, as the camera will rotate around the parent’s axis.
If the hierarchy is correct and it is something else that is causing your problem, please don’t hesitate to respond and I’ll attempt to assist you further.
I restarted with a fresh 4.7.6 FPS C++ project and am getting the same lack of results. It isn’t something being wrong, rather it is an inability to change how mouse motion affects the view.
The GIFs above are how mouse left<->right movement affects the view in my project and also in a new FPS project, with the first GIF being on a horizontal floor and the second being on a sloped floor. The weirdness of the second GIF is because the camera is rotating around the Z axis but the hallway is 40 degrees off horizontal.
I am trying to find what to set/change so that left<->right motion of the mouse rotates the camera around the axis normal to the floor rather than around the Z axis.
I know how to find the normal of the floor, but I cannot find where to change the axis of rotation of the camera.
I tried everything I could find related to the character, the capsule, the controller and the camera that had ‘rotation’ in the name. None of them changed the axis of rotation of the camera.
Is there such a function somewhere? It seems there must be since it would be used in any sort of flying game. I checked out the flying game sample, but it doesn’t use the mouse at all so I didn’t find an answer there.
I believe you’re right and it’s something to do with the calculations of the mouse input but I cannot tell without seeing your actual code.
Can you send me your project itself so that I can look at the problem at its core and attempt to resolve the issue? If the project is too large for you to upload, just the code files should be sufficient.
The test project was a bit over the limit so I put it on a server you can grab the project from, I figured that would save you a little time vs. sending just the source.
The player start is right in front of a box that runs the code on overlap. Everything I tried is in NoSlouching.cpp commented out, so at the moment it does nothing. No other files were changed from the initial project creation.
If on game start you look up a bit you a green line. If you look at that and move the mouse left/right you will see the line appear to rock back and forth. Looking to the right there is a line, which appears to move back and forth normally. My goal is the make it so once the player moves forward and enters the box the control/camera/whatever is changed so that looking at the green line and mousing left/right the line just moves left/right without the rocking.
The only way you’d be able to turn the camera as if you weren’t looking up would be to modify the camera controls themselves instead of the character. You may want to rotate the camera to match the incline and turn the camera itself based off the input of the mouse instead of using the default input functions like AddControllerYawInput, which is deeply nested in the engine’s files.
I hope this is enough information to help you through this.
Here is a video that solves a similar problem, but it seems a little bit too simple. If it’s possible for similar solution could be implemented in UE4 with the same level of simplicity, it would be awesome if someone could post a follow-up.
Also, these links seem like they could be potentially useful as reference for implementing a camera that uses a unique or variable axis of rotation. The requirements for the below problem are probably overly complicated compared to this one however, so the solution might not be usable as-is:
(I’m also trying to solve a similar problem where I’m trying to change the camera’s axis of rotation [which direction is “up”] and maintain smooth camera controls, so some sort of definitive solution would be great)