Head Mount Display Camera Turn (with Keyboard)

Hey guys,

i wanted to implement a way to turn my Camera with the keys Q and E (+30 and -30 degrees).

I have 2 Problems. If i use the Blueprint without the -1 float component, the Camera turn 30 degrees (in the opposite direction) with the first Keypress and with the second Keypress it turns back to it’s previous position. Because the set Base Orientation and Rotation Offset subtracts the value it gets from the base value. 0 - (-30) = 30 (that’s why the opposite direction), but somehow the next value, will be 0 again, thats why it gets the previous position after a second input.

That’s why i added the -1 component. It works as long as the Head Mount Display Yaw is 0, if it’s not 0, the value will differ from 30 degrees. For Example if my HMD Yaw is -60 Degrees and i press Q, the camera turn to +90 Degrees, because of the -1 component.

Can someone help with this? I am completly desperate about this and have no idea how to solve it.

Well I try to explain it in pseudo code with overexpressive variable names:

NewYawDegree = CurrentYawDegree + 30;
if (NewYaw >= 360.f)
{
    NewYaw = NewYaw - 360.f;
}
CurrentYawDegree = NewYawDegree;

And for your tunr in the other direction:

NewYawDegree = CurrentYawDegree - 30;
if (NewYaw < 0.f)
{
    NewYaw =  360.f + NewYaw; // NewYaw is negative here so minus is calculated
}
CurrentYawDegree = NewYawDegree;

Of course you can combine it like that:

NewYawDegree = CurrentYawDegree + PositiveOrNegativeChangeValue;
if (NewYaw >= 360.f)
{
    NewYaw = NewYaw - 360.f;
}
else if (NewYaw < 0.f)
{
    NewYaw =  360.f + NewYaw; // NewYaw is negative
}
CurrentYawDegree = NewYawDegree;

If PositiveOrNegativeChangeValue can be higher than 360 or lower than -360 normalization could be done in while loops. Shown here in a more condesed way:

NewYawDegree = CurrentYawDegree + PositiveOrNegativeChangeValue;

while (NewYaw >= 360.f) NewYaw = NewYaw - 360.f;
while (NewYaw <= 360.f) NewYaw += 360.f;
if (NewYaw < 0.f) NewYaw += 360.f;

CurrentYawDegree = NewYawDegree;

Optionally you can also turn your Pawn, instead of recallibrate the HMD. Maybe that makes more sense if the pawn can move also.

Thanks a lot, but is there a way to get this done with Blueprints?

You need the nodes +, -, <, >, <=, >=, branch (for the if), and WhileLoop. I have no to solve it for you and make a screenshot, but it should be super easy or at least good practice if you really wanna work with UE4.

I just thought it might be even easier if you just use Add Controller Yaw Input and give it the value 30 or -30. Should do the job on a Pawn or Character.

Try to figure it out, this is where proficiency is comming from thumbs up

Good Luck!

I’m still having the Problem, that my values are extremly weird, eventhough i have 30 degree turns, my camera turns like 100 or 120 degrees per Key press.

Whoop ok I give it a try…

You’re right. I’ll figure it out. But we are close :wink:

Just tried it out, it doesn’t work properly for me. The value the yaw is changed is still weird. I only need 5 Q Presses for 360 degree turns.

Ok I found it and I wasn’t aware of this too, it’s kind of undocumented 0o

In the PlayerController source you find this call resulting in this

void APlayerController::AddYawInput(float Val)
{
	RotationInput.Yaw += !IsLookInputIgnored() ? Val * InputYawScale : 0.f;
}

So the PlayerContoller has a value called InputYawScale that ist default set to 2.5 in the BaseGame.ini

So we can either set it by hand like I did it in the Screenshot or you can do it in the DefaultGame.ini in your project’s config folder:

[/Script/Engine.PlayerController]
InputYawScale=1.0

43728-capture2.png

Did this help you Chaptrap?

A little late now, but this is what I was using

First, i’m sorry for no reply. Haven’t seen your solution. Second i’m a little busy at the moment and don’t have my hands on the Oculus right now. I’ll try this next week when i can work with the Oculus again. But thanks in advance, this looks promising :smiley:

Okay, i finally was able to get my hands on the Oculus again.
Your solution worked very well. This is exactly what i wanted, so thanks a lot!

I’m glad this helped you!

Would you like to accept the answer? You know, to indicate it for others and for my Karma Score =)

P.S. 8 Days without VR development? 8 hours ok, one has to sleep now and then, but 8 days… :wink:

Well i was at home, during holidays (in germany) and i can’t work with the oculus on my home computer :smiley:

Hope you had a good in Germany!

Argh I corrected a typo and then all the green was gone. I took that chance and extracted the comment as answer. Maybe you can accept again? I did not expect this to break the mechanism sorry.