Auto-Rotating a Pawn

Hello!

I’m having trouble figuring out how to smoothly auto-rotate a pawn on it’s X Axis back to zero after the user releases the thumbstick. It seems like I should use Set Timer by Function Name that is triggered by the Gamepad Right Thumbstick Right and Gamepad Right Thumbstick Left Released event. The auto-rotation from the current X Axis rotation to to X Axis = 0 should take .5 t0 1.0 seconds; I don’t want to just snap to zero.

The logic seemed to be that I should create a function that decrements the current X Axis rotation until it’s nearly 0 and have the Set Timer by Function Name loop until the Pawn’s X Axis is 0 (or nearly 0).

So if I want the auto-rotation to take .5 seconds, I need to to decide on how many times I want the function to loop and calculate a decrement value.

For example, if I want 120 increments of rotation from the current X Axis to 0 to occur over .5 seconds, I would set the Set Timer by Function Name Loop time to .5 divided by 120 which is .004166. If I wanted 500 increments, I would set the Loop time to .001.

I have a function that works - eventually. The pawns just spins around and around on its X Axis until it’s nearly to 0 then stops.

I feel like I’m overthinking this and making it far more complex than it needs to be. Can anyone offer a suggestion or better idea?

There is two options, a set rotation option and an add rotation option. If you use set rotation it locks the rotation sorta and you have to deal with y and z axis too so it’s usually best to use add rotation when you can. Make a function timer with a handle, set it to run when you let off the stick, when you trigger the stick invalidate the function handle. Inside the function make a branch, the true condition for the branch is the pawns world X rotation = 0. Drag off true to an invalidate timer node and invalidate the timer when the rotation is 0. Off of false, get world rotation of the pawn you want to rotate, multiply its x value by about .01, and add it to its world X rotation. This will cause the rotation to be faster when it is rotated more, and then smoothly stop when it gets to 0. If you want it to be completely linear transition that can be done too by adding a new float variable, setting it to the pawns X rotation on function start, then doin some simple subtraction with the float. But from what you are saying it sounds like a fast to slow rotation is better. If it rotates too fast at first, clamp the negative and positive values.

jay001020,

Thank you for the directions. I’m fairly new to Unreal Engine and Blueprints but I gave it a shot. Here is what I came up with:

In the Event Graph:

In the Function:

The function fires and I end up with the same result in my original post; the pawn just spins around and around on its X Axis until it’s nearly to 0 then stops.

Can you or anyone else point out where I’ve gone wrong?

Should look more like this. If you want the mesh to auto rotate to 0 on the axis when it gets really close, plug in that last part that i left unplugged. You will have to adjust the number that gets multiplied to change rotation rate to what you want. Also adding local rotation adds rotation in a different way then world rotation…I am not sure which one you want but world rotation is a little more common.


Here is a spring arm example thats actually been tested. When you let off of right click the spring arm rotates back to zero if you rotated it at all. Sometimes the number that gets multiplied has to be a negative. For the spring arm you usually want relative rotation cause it is a child.