Make Camera only moveable between two angles

Hey guys,

your certainly know the Game “DayZ”. I love camera control from the game. So I tried to copy them.

Now I’m so far that I can turn my head with “ALT” and then I can run on my way. But I can fully rotate the camera around my character.

But I want the camera moves only between two relative angles.

See image:

I am thankful for any suggestions.

:slight_smile:

i think i have a solution (not the best)

first i need the relative angle of the Cameraboom:

float yawMax = CameraBoom->GetComponentTransform().GetRelativeTransform(RootComponent->GetComponentTransform()).GetRotation().Euler().Z;

after that i push the camera back to the moveable angles:

if (yawMax <= -110)
	{
		AddControllerYawInput(1 * BaseTurnRate * GetWorld()->GetDeltaSeconds());
	}
	if (yawMax >= 110)
	{
		AddControllerYawInput(-1 * BaseTurnRate * GetWorld()->GetDeltaSeconds());
	}

Unfortunately, here the camera jerks back and forth.

Is there a boolean variable which, if it is false, prevents the camera movement?

Still need help :slight_smile:

thank you

Hi,
I found your post because I had a similar problem. I wanted to restrict the camera view to the limitations of the head.

I solved it with this solution:

In Character::BeginPlay() override:

APlayerController* PC = Cast<APlayerController>(GetController());

PC->PlayerCameraManager->ViewPitchMin = -90;
PC->PlayerCameraManager->ViewPitchMax = 90;
PC->PlayerCameraManager->ViewYawMin = -90;
PC->PlayerCameraManager->ViewYawMax = 90;

I’m not 100% sure if the syntax is correct, I can’t look into my code right now (If it doesn’t work, I’ll look after it this evening). I hope this helps!

PS: If you want to totally block pitch or yaw, just set the same numbers to min and max (e.g. 90 and 90). This was my first bug when finding this solution.

It may be that it’s not quite right for your case, because my player is sitting and won’t move. Maybe you have to get the current rotation and add or subtract the 90(or whatever you wish) degrees to it. And after this, set the ViewMin and Max. Like in this pseudocode:

Rotation CurrentRotation = GetCurrentRotation();

PC->PlayerCameraManager->ViewPitchMin = CurrentRotation.pitch - 90;
PC->PlayerCameraManager->ViewPitchMax = CurrentRotation.pitch + 90;
PC->PlayerCameraManager->ViewYawMin = CurrentRotation.yaw - 90;
PC->PlayerCameraManager->ViewYawMax = CurrentRotation.yaw + 90;

But actually, this is just a guess of mine.

Otherwise it could be, that it’s better to use the upper one (without Current Rotation) in the Character tick method. This way it set’s the limitation every tick… Well you have to try it out - I’m quite new to UE4.

Great, I’m glad i could help you a bit!
Unfortunately, as I said, I’m new to UE4 and I don’t know yet how to call a “on-release-button” function. But I think there must be one. And you already have the oldYawRotation, so you would have to reverse this:

OnStopLooking()
{
APlayerController* PC = Cast<APlayerController>(GetController());

// Reverse!! now ADD the 90 degrees again to MIN
PC->PlayerCameraManager->ViewYawMin = oldYawRotation.Euler().Z + 90;

// Reverse!! now SUBTRACT the 90 degrees again from MAX
PC->PlayerCameraManager->ViewYawMax = oldYawRotation.Euler().Z - 90;

}

So you only have to figure out, how to call an event on releasing the button.
Maybe someone else can help out here?

Well, if I get it right, you want to set the ViewMin/Max to its previous float value. How about fetching it before changing?

APlayerController* PC = Cast<APlayerController>(GetController());

float standardViewYawMin = PC->PlayerCameraManager->ViewYawMin;
....

Just a guess… :wink:

PS: Of course you have to set it back to ViewYawMin when releasing ALT.

Great! I’m glad that you can go on now :slight_smile:

Oh very well, thank you!

It works great. Just had to change the following:

if i press ALT, i call

StartLooking()
    {
            oldRotation = Controller->GetControlRotation();
    	oldYawRotation = FRotator(0, oldRotation.Yaw, 0)
    }

is set the Rotation, so that the Character can walk his way.

While ALT is pressed, i call:

OnLooking()
    {
            APlayerController* PC = Cast<APlayerController>(GetController());
    	PC->PlayerCameraManager->ViewYawMin = oldYawRotation.Euler().Z - 90;
    	PC->PlayerCameraManager->ViewYawMax = oldYawRotation.Euler().Z + 90;
    }

if i released ALT i want to reset the ViewYawMin/ViewYawMax back to standard. How could i do that? :slight_smile:

Thank you for your help!!

I still know how to call the realeasing Method :slight_smile:

But unfortunately this way does not work. if I found a solution, i’ll come back. Thank you really for your help :).

I have the solution,

in the EndLooking() method:

APlayerController* PC = Cast<APlayerController>(GetController());
	PC->PlayerCameraManager->ViewYawMin = 0;
	PC->PlayerCameraManager->ViewYawMax = 360;

And i can rotate my Character :slight_smile:

So thank you, you’re the best;)

yeah that was the right way,

only the following

 PC->PlayerCameraManager->ViewYawMax = 360;

must be change to:

 PC->PlayerCameraManager->ViewYawMax = 359.999

this works :wink: