How do I make an object rotate smoothly when clicked?

Hi,

I’ve created a 6 sided “cylinder” that I want to rotate smoothly when it’s clicked by the mouse (think a reel of a slot machine). What I’m trying to do is, when the player clicks on the cylinder, a random number from 0-360 is chosen (for the number of degrees it should spin), then the cylinder should rotate for a certain number of seconds, and then it should stop at that number of degrees. I’ve figured out how to get it to rotate to a random degree when it’s clicked but the rotation isn’t smooth - when it’s clicked, it immediately rotates and stops.

for your help.

Hi riley,

There are a few ways to do this. The way that first comes to mind if you only want to do this in Blueprint is the setup shown in the screenshot.

In that setup I set a float variable based off a random number. Then I made a timeline that goes from 0 to 360 over a couple seconds and set the rotation based off that timeline. While the cube is rotating there is a branch that checks if the current rotation matches the random number generated earlier. Once this is true the cube stops rotating and is then put into place since the check isn’t 100% accurate. This is done with a simple timeline that goes from 0 - 1 over a second and lerps the cubes rotation to the random number.

How I would actually go about doing this though is to create a series of animations. First an animation of the slot spinning a few times. Second animation rotates the mesh 360 degrees over a set period of time (I will use 1 second for this example). In blueprint I would then set a random number like 56 for example. You would have to use the formula x/360*t = y where x is the random number, t is the number of seconds, and y is the time to stop the animation. That will ensure a smooth rotation and that it stops at the desired point each time. You can also have a third animation of it clicking into place if you want.

Let me know if that helps,

Ed

Hi Ed,

for the response. I actually read through a bunch of different answers here and kind of mixed a few together to get a working result. From my understanding, the timeline tells it to go 360 degrees in 2 seconds and the random number multiplies that from anywhere between 0 and -1 so that it will rotate a random number of degrees each time. Here are screenshots of the blueprint I created as well as the timeline in case anyone is interested in the future.