Limiting 360 degree rotation

Hi Everyone
I love the Unreal Engine; some things I have a natural affinity for but Ive run into a snag in blueprint scripting. Im using the Y mouse axis to control the rotation, works great, no problem, infinitely. However I do not want the object to spin infinitely; Id rather see the object rotation stop at +45degrees or -45degrees from initial rotation no matter how far I move the mouse. Ive tried using tutorials and tips from other posts but nothing has worked yet.

Basically, move the mouse up, the object should spin upward but stop at +45 degrees from initial rotation. Move the mouse down, object spins downward but no more than 45 degrees from initial rotation. The maximum rotation would be a total of 90 degrees maximum from the +45 extreme top, and -45degrees to the extreme bottom.

The object will never face the camera; at least not yet. See screenshot.

90788-rotation_problem.png

I made to try. Please take a look at the image.

Strictly speaking, not in 45 degrees and -45 degrees. But it could be controlled in the near value!

The object still spins infinitely according to mouse Y axis value. Some clarification needed is when the object rotation nears either +/- 45degrees it should stop rotation although the mouse is continuing its movement. I do see what you are doing with the >= Booleans. Makes sense but still is not limiting/locking the rotation at a specified angle.

Im going to take another look at the blueprint and the meshes. This might be the answer. Some tweaking will be needed but this looks to be a step in the correct direction. The angle of the rotating object should be compared to a static angle to determine minimum and maximum angle values?

Well, please forgive me because while the responding translation of might have deviated from the intent.

If that contains the angle from the beginning, you must first be calculated.

For example,

Limit value = Default value +/- 45 degrees

Of course I want to limit the value, that’s the point of this question. We have just used different terms. Thank you for the response.

The logic is this: If Arms (Get Rotation) less than 45 and axis value greater than 0, or if Arms (Get Rotation) greater than -45 and axis value less than 0, then add rotation

From the output of the pitch you can clamp angle (it takes a float as input and looks similar to the clamp float). That should do the trick.

Everyone has been correct thus far; Im looking forward to plugging this in and giving it a go after work! :slight_smile:

Everyone has been on track with this one. This one looks correct. I might use >= and <= for the GetWorldRotation output; I’m “thinking” that if it is at 0, 45, -45, rotation may be disabled. I’ll plug it in and respond this afternoon! :slight_smile:

I’ll also try clamp angle with Vaei’s setup. It looks correct and minimal amount of code is what we should strive for.

Optimal, instead of minimal, rather :slight_smile:

Yeah this is the better way, answered while tired :slight_smile:

oh! That’s new for me!

Progress has been made. It is stopping rotation but not at the desired angle. Also, the rotating object is gradually rotated into a ‘dead zone’ where no rotation occurs in either direction. Also, it is the pitch that is being controlled, but the angle that is to be measured for condition is Roll (X), not Pitch(Y). I only discovered this using the Print String function. More tweaking is needed; it is definitely stopping now. :slight_smile: