Hoopla70
Hoopla70

Reputation: 111

Unreal Engine: Constrain a pawn's rotation between two angles

I'm working on a short Unreal Engine 4.9 blueprint for a friend, but I am not familiar with the unreal engine at all, and I'm about to pull my hair out. I've been searching online for about 2 hours, and I can't get it.

What I'm trying to do is get the roll of a object, derived from the pawn class, and lock it in between two angles. In pseudocode, do this:

if MyObect.Roll < -50,
    MyObject.Roll = -50;
if MyObect.Roll > 50,
    MyObject.Roll = 50;

Any sort of help or pointing in the right direction would be a huge help. I've seen some post using a player camera manager, and no luck from that thus far. Thanks in advance.

Upvotes: 0

Views: 1879

Answers (1)

Bas in het Veld
Bas in het Veld

Reputation: 1322

First thing to do in such a situation is print your values, e.g. using UE_LOG. You'll notice that your values are often between 0 and 360 instead of what you might expect yourself (-180 to 180).

So, you'll need to 'normalize' your angles first, to get them to be between -180 and 180. That way you can use the code you posted above :)

if (MyObject.Roll < -180.0f) MyObject.Roll += 360.0f;
else if (MyObject.Roll > 180.0f) MyObject.Roll -= 360.0f;

Hope that helps!

Upvotes: 1

Related Questions