Clamp Rotation

Hi,

We have a Z float value, that we get by breaking Rotator.
It should be clamped to the closest C value, once this Z value falls lower than C value.

For example if C1 is 350, C2 190 and Z 340 (if we use node “Clamp Axis”), then Z should be clamped to 350. If Z is 200, then it should be clamped to 190.
Keep in mind, that the C values are not const, they change as the player rotates.
image

I managed to clamp it, once it falls below the C2 value.

The problem is the C1 value. In the example provided above, if we would aim left, below the C1 value, our Z would go up from 0 to 360 and then down to 340, try to clamp at 350 by, I Suppose, going full circle from 0 to 350, clamp at C2, continue rotating, until it reaches 351, unclamp from C2 and go so on in a circle.

Here is a video of it in action:

How can I solve this problem? I need help

Hey @sShArLoTaNn!

I think you need to use negative numbers, here! Have you tried using -90 as your minimum for your left aim? Rotating left is negative rotation, after all. :slight_smile:

What do you mean negative numbers? In my case my numbers range from 0 to 360.

And even if I had negative numbers I cannot use const numbers like -90 in min or max, because my character is not always looking up, he can also rotate and so the C values with him.

I was confused by your comment until I noticed, why are you using world rotation to move the arm? Typically you want the actor to be in world space, and anything underneath it to be using local space, so it’s all relative to the actor root. Especially if you’re going to be turning.

Can you zoom out a bit and show us the surrounding code? You may be able to replace a very large amount of this by switching your clamps to something like min -100 max 100 and using local rotation (So the rot would always be Player Z -100 to +100 no matter the direction you turn :slight_smile: ).

ooh I see what you mean by rotating in local space. I will try it out

1 Like

So I think it is almost solved. Two things left.

This Z value is in World Space, but if I want to rotate the bone in local space, Z should also be in local space too then.
Here I tried to transform Z rotator to local space, but it doesnt work (if I am aiming forward, Z is not 0):
So I need some way to get the Z value to be in local space, maybe my initial approach to get the Z is wrong? Or maybe I am transforming it wrong?
image

And the other thing is, later I am using this Z value in Anim Blueprint to modify arms rotation:
image
image

Is it the correct way to do it?

Im sorry, that I am asking so many questions on, I think, very basic issue. I just never worked so intense on rotators in UE.

It’s not really a basic issue, it’s kind of an edge case, honestly. A jigsaw puzzle that’s completely white with 10,000 pieces is still just a jigsaw puzzle. Sure, you could call it simple because it’s a jigsaw puzzle, but the extra details change the game. :slight_smile:

Here, check out this thread. It’s an extremely similar situation to what you have going on! :slight_smile:

1 Like