How to constrain camera/controller rotation?

Hello!

For now I look in third person BP template.

Here used SpringArmComponent to attach and control camera.

Camera rotation behavior provide ability to look at character from bottom and from above. It looks like rotation set between -90 and 90 degrees or something similar.

How can I constrain this to different values, to avoid problem from “screenshot” attachment, when camera cuts player’s mesh?

screenshot.jpg

Thank you!

Hey Dmitry,

So first you will want to turn off “Use Controller Rotation”, next we are going to need to go into the eventgraph and tell the BP to clamp the camera rotation.

I have added an image that you can reference while following along with this mini-tutorial:

The simplest way to do this in the 3rd Person template is to start by getting the Camera Boom, then dragging off to get Transform > Relative Rotation. Break the relative rotation, so you can get Pitch and Yaw. Drag the two InputAxis events out into Add Float nodes. Add your Pitch from Break Rotator to your InputAxis LookUp. Add your Yaw to your InputAxis Turn. Separately Clamp both Add’s outputs. In the Clamps, you can set the angle to which you can rotate your camera. Drag off a Clamp and create a Make Rot node. Plug your Pitch clamp and Yaw clamp into their respective nodes. Add an Event Receive Tick. Drag off the execution and create a Set Relative Actor Location. Plug your Make Rot output into the New Rotation and your Camera Boom into Target.

In the image you may notice the InputAxis LookUp multiplies by -1 before adding. That will change it from inverted looking to standard. You can also see what my clamp Min and Max are; With that setup the camera can lean up and down slightly and turn to see a profile view on the character. Please let me know if you have any other questions.

Thank you,

Alexander

2 Likes

Hello again!

For with new build I tried to implement this again.

I set “Use controller rotation” for camera boom to false. And this is my setup:

bp.jpg

So, I need that character to move by Forward/Right vector relatively to camera look up.

As you can see, I get camera Forward vector, then break and set it’s Yaw for movement.

BUT, camera boom attached to character, and when it moves, camera rotates in unbelievable directions.

With your setup in third person BP template, View rotation is not attached to camera, but here is different situation and I stuck with it.

Maybe its better to use Rama’s method?

Or can I request to add some “clamps” to your view rotation by default?

Thanks!

Also I tried to make that Clamp in Player Controller, and works like in previous build - it can’t reach negative axis values and resets in 0.

Hi Dmitry,

I have looked into the node changes and there have been further alterations since my last post, making it invalid.

Lets approach this from another angle and see if it works better, because we are doing a “hacky” work around using Blueprint nodes.

Could you try creating a PlayerCamera Blueprint, then set the min and max rotation values in it’s defaults. Open your MyController Blueprint and in it’s defaults under Player Controller, set the Player Camera Class to the PlayerCamera you created earlier. Then PIE and see if that is a simpler fix for what you are trying to accomplish.

Let me know if this works for you.

Cheers!

Hello Alexander!

Thank you for reply. I tried PlayerCamera Blueprint and it works fine.

I thought about separate camera class, but because of Epics not used it in TP sample I just wait for your answer.

Thank you again!

Are you sure that axis value can be negative?

Please, Look my video on FTP.

/FTP_Dropbox/redbox/BP_TP.mp4

Hi Dmitry,

That is a known error that has since been resolved. Your rotations will not reset and jump like what you are seeing in Beta4 in the future release of the beta. I apologize for any confusion because of this.

Thank you,

Ok, I see.

Thank you for help!

If you implement a custom playercontroller class you can constrain the rotation via

//in pc class
SetControlRotation

you can determine the current controller rotation with

//in pc class
GetControlRotation()

You’d do this in an overrided playertick function

see my tutorial on a custom HUD to give yourself idea of how to set up a custom player controller class

http://forums.epicgames.com/threads/972861-Tutorial-Compile-C-for-UE4-Code-Samples-For-You-(New-Play-Animations-from-C-)?p=31651318&viewfull=1#post31651318

note that FRotator values are in degrees, yay!

Hi Dmitry,

Thank you for your question. Could you please give us a screenshot of your components where I can see your parenting setup and SpringArmComponent properties?

Thank you,

Alexander

Hello Alexander!

It’s from simple 3rd person BP template.

Here is my character BP

Hello,

I am not sure if there is a better way or not, but the only way I have found is by using the “Get Player Camera Management” block, in there you will find two variables “View Pitch Min” and “View Pitch Max” if you set these manually prior to reaching the “Add Controller Pitch Input” this will restrict the camera movement between the min and max pitch.

Call it a manual clamp :wink:

to find the correct segments you will need to have “context match” unchecked.

the other way is to create a class from scratch and manually code the restriction in, for me the BP is the easiest way and it actually works!

Bear in mind I use Unreal Engine 4.10 (not sure if it is in the older versions or not)

How ever the principle is the same as for the YAW, see second screenshot.

I hope this helps

Screenshot below:

1 Like

This has helped a lot, however… This seems to only work on “world Relataivity” not local to the pawn… As in, when i try the same thing pointing the opposite direction my camera gets spun around. any way to use this but lock to the characters local forward vector? i’ve tried a few ways but can’t figure out what is going to work yet.

Not to necro an old thread, but none of these answers actually work. The closest was the Get Player Camera Manager suggestion but this only works with WORLD rotation not relative.

There has to be an easier way to clamp the rotation of a camera relative to the pawn.

Essentially I’m trying to create a First Person perspective with a body. I’ve added Aim offsets to the third person character and socketed the camera to the head bone and deleted the spring arm. Problem is, the Aim Offset requires Use Controller Yaw to be off but for the “First Person” effect to work, the rotation yaw has to be on, otherwise the camera can freely rotate in 360 degrees. The Pitch is clamped by default, why can’t there be an option to clamp the yaw?

Still works in UE5.03

You don’t have to call the setters on the input tick (BeginPlay will do the job)

This worked perfect, thank you.