how to limit rotation of static mesh using add relative rotation node

Hi guys, i need help in limiting rotation of static mesh, i use a add relative rotation node, the problem is when i use a clamp node, from my axis mapping , it affects the rotation speed and not the rotation limits. any ideas what im doing wrong?

1 Like

You’ll want to manually add the rotation in combination with a SetRelativeRotation node rather than using an AddRelativeRotation.

After adding, before setting, you can clamp the Y value using your current method.

when you say manually adding the rotation, do you mean creating a variable that would contain the limits of the rotation? if possible could you show me an example?

the issue ive noticed with add relative rotation is that its not smooth but immediate, and im looking to get smooth rotation like add relative rotation gives

I assume you mean set.
There is no difference between add rotation and adding using set rotation.

Oh yes sorry, i mean i have issues with set relative rotation, thats why i always used add relatative rotation instead. Maybe if i use some lerp and timeline nodes it would smooth the rotation that way?

There is no difference between Add and Set rotation in this context. We’re manually creating an Add rotation by doing the addition ourselves. As long as you get the relative rotation and not the world rotation, you’re good.

Lerping and timelines aren’t things you can use with an input- input is called too often.
Seeing as it’s an axis value, most cases would see it being called every frame- the movement would be as smooth as possible already.
If something is not looking smooth, there is a cause elsewhere.

2 Likes

Im still new to this, so I’ll try figure out why its not smooth. What i noticed with the input values, with add relatative rotation, the value affects the speed, and with set relative rotation the value affects the rotation degrees, then that would mean i wouldn’t even need to clamp the set relative rotation i could just set input values in the project settings right?

Add a print statement printing out the value of AxisValue after bucketControl. You’ll get a better understanding of what the axis is. You wouldn’t be able to clamp it, and even if you could- that would only clamp the maximum speed.

This’ll look a little daunting, but this is the source code for set and add relative rotation:


Ignore how we pass in an FQuat during AddRelativeRotation instead of the FRotator that we actually pass in blueprints- the function we use in blueprints is the K2_AddRelativeRotation which acts as a wrapper function.

In SetRelativeRotation (1393), we’re simply checking if it’s not the same rotation (1395).
If it’s not (1398), we set the relative rotation and location using our current location and the new rotation.

In AddRelativeRotation (1402), we first get the current relative rotation (1404, we convert it to a quaternion). We then (1405) multiply the DeltaRotation (the rotation we’ve passed in and want to change the rotation by) by our current rotation (quaternions combine when you multiply them). Finally, we set the relative location and rotation using our current location and new rotation.

There’s only one major difference between the two. One adds, one sets. They don’t do it with different functions or on different timescales with different smoothness or anything like that.

1 Like

you know ive been dong so much research on this, and i have to disagree with you on this, the adding of rotation would have a smooth effect while the set would be immediate, ive created a new project even to see if im wrong but each time i get the same effect, unless you could upload a video where you use a set relative rotation and it has a smooth rotation to it so i can se this for myself.

Maybe something like this is needed. This is on a key press but I would imagine it would be the same on any input down.

As I’ve said and shown, adding rotation simply adds the rotation and sets.
The image I showed is of the source code for a SceneComponent.

But here’s the video. I had to nuke the resolution so it could fit in the 30mb limit for these forums, but you can still make out important details.

2 Likes

okay, ive tried it myself and it works, but where in this BP would i add the clamp node to limit the rotation? thanks alot though , you’ve been alot of help .

1 Like

You would clamp the axis of rotation you want clamped- so you would first break the rotator, clamp the axis, and then make a rotator with that clamped axis.

Here’s an example using the same cube as before that simply rotates in place and then flips the rotations direction to stay within the clamp:

When clamping, use one of these nodes:


Clamp angle assumes the directions are between 0 and 360 while clamp (float) assumes they’re between -180 and 180.

Here’s how you would clamp just the vertical (yaw) axis:

Im definitely going to try this and give you feedback.

another quick question though, the branch node in the BP, whats that for

You can just completely ignore the top example- that’s just what I was using to confirm everything worked.

What you’ll actually use is this:

1 Like

this works perfectly, thank you so much for this, seriously after months and months finally i can now continue with my project, thanks a million!!! can you recommend any courses on blueprints for me to learn abit more?

Unfortunately I don’t really have any single course to recommend. I started unreal watching full tutorials on entire games, but I wouldn’t recommend any of them since they taught many wrong/lacking things.

For smaller scale things, I do have some recommendations.
First- I recommend Mathew Wadstein for any individual node. He’s covered pretty much every node you’d need to know about.
For anything non-blueprint, I’d recommend PrismaticaDev. He doesn’t have any tutorials on blueprint, but he’s great for everything else (ie animation, particle effects, materials, audio, and a neat devlog).

Also just well-produced content- might be nice to just watch some on something that piques your interest:

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.