In blueprint, how do I rotate a static mesh to multiple set orientations?

Hello everyone,

I would like to be able to have a mesh’s orientation change depending on which component overlap is triggered.

Here is a video of what I would like to achieve:

If the dial is set to 0 and then the player steps on 45 > the dial will rotate to 45 over 2sec.
Then if the player is standing on 90 > the dial will rotate from 45 to 90 over 2sec.
If the player steps on 0 > the dial will rotate from 90 to 0 over 4sec.

Like that and so on. There will be more than 3 triggers, I will have a 8 triggers at 45degree increments. 0, 45, 90, 135, 180, 225, 270, 315.

Here is the blueprint of what I tried:

It sort of works, but the problem is when I go to the next trigger (I want to go from 45-90), the animation will jump back to 0 and then rotate to 90. What I want is for it to start at whatever orientation it’s currently at, and then rotate to whichever orientation I trigger. Also the rotation speed should be constant no matter the rotation distance.

It seems like it should be pretty straightforward but I can’t seem to figure it out. Any help would be greatly appreciated. :heart:

I suggest to use tick for this. The idea is to define floats: CurrentAngle, TargetAngle, Speed. On tick, if CurrentAngle != TargetAngle add or deduct Min(Speed*DeltaTime, %actual-distance-to-target-angle%) from CurrentAngle depending on required rotation direction (which, depending on exact task, may vary). And ofcourse set your’s actor rotation to CurrentAngle.

Then each “overlap” you talking about should just set TargetAngle on your actor.

Timelines are not solution for generic problems like this, as they just return a set of hardcoded values from attached curves.

Thanks for the reply. Yeah On Component Overlap and Timelines are not necessary. It’s just the only thing I could think of. I watched several tutorials of things that I thought looked similar to what I wanted to do, like opening a door and moving a platform. So that’s where that idea came from.
Unfortunately I don’t know much about CurrentAngle, TargetAngle etc, and I can’t seem to find those nodes in Blueprint (i’m still learning more and more each day). If you don’t mind, could you send a screenshot of what you mean?

Since you want something to happen in a specific timeframe, the Timeline may be the way to go, actually. Consider the following:

  • the timeline:

  • and the rest:

This can be improved to fit desired needs, like this:

If the player steps on 0 > the dial will rotate from 90 to 0 over 4sec.

You can modulate the rate at which the timeline plays with:

image

The 2s timeline will now last 4s.

Thanks for your reply!
I followed along what you did but it doesn’t appear to work:

Can you see something I did wrong? I even tried adding a Cast to FirstPersonCharacter after the OnComponent Begin Overlaps. That did nothing.

Timeline is also created like you showed minus the bezier curve.

image

Also do I attach this to the timeline or do I leave in unconnected to anything? If I need to connect, does it matter if it goes before or after the timeline?

Two variables. Starting and Target rotation. You only have one and use the same one to lerp.

1 Like

You could detect rotation delta between start and target to see if enough is missing to warrant a 4s long TL.

Just before the TL starts. It has to be connected, ofc.

Thanks! That made it spin (also fixed the connection to Play from Start)! However rather than always rotating to the same spot each time, it’s just rotating by the value I added in the TargetRotation.
Think of it like a clock, if I want the hand to go to 3oclock it should go to 3, when I tell it to go to 6, it should go to 6, and so on. Does that make sense?

It should work as you described already. Can we see the updated script?

Why add values?

use Finterpto node:

Set target to desired value, and process/update mesh on tick.

OP wants it time based.


Gave it a go and it seems to work more than fine, version with the TL playrate incorporated:

Is this close enough? You may want to flip some axes - depends on how you need it to work.

1 Like

Great!!! This works! I think those nodes you added did the trick! However, the rotation speed is not constant. For example, if it take 5 seconds to rotate 45 degrees. It should take 10 seconds to rotate 90 degrees. Right now what is happening, is no matter how far it’s rotating, the time it takes to make that move remains the same.

the rotation speed is not constant.

It seems to be fine in my example, no? Rotating from 3rd to 1st is twice as fast, taking the same amount time as going from 1st to 2nd. Or am I really getting it all wrong.


Seeing now that more is needed that what was originally requested, I would have set up the whole thing slightly differently, to be honest.

Still, it’s a matter of remapping the rotation delta onto the TL playrate. You have only 1 and .5 speeds. You will need two (?) more speeds here, I guess.

Play with something along the lines of:

Looks about right?


Also, if you do not need it to last precisely X seconds, there are other ways as @Nawrot mentioned. Not only is there rInterp To, but also its rInterp to Constant equivalent.

I’m sorry for the confusion. I did however mention in my original post that I would have more stopping points on the circle and that I wanted a constant speed. I’m sorry my original message wasn’t clear. I appreciate the time that you and everyone else have taken to help me.

I made the changes that you mentioned in your screenshot and that does that trick! Thanks so much!!! If you don’t mind me asking, how long have you been working with Blueprints? Just trying to get a sense how long it might take to get as good as someone like you. :slight_smile:

1 Like

I did however mention in my original post

You did, indeed. My bad! It’s probably for the better, tbh. I would have over-engineered something big time, surely.


image

Let’s see if I can make it 10 years!

Oh, another question: I was looking again at your screenshot. Did you connect all of the Set Targets to the one Set Connect? If so, only one of the sets needs to connect to the Delta (Rotator)?

Haha. I would have loved to have seen how that over-engineered version would have looked. I probably would have thrown my computer out the window after seeing it. haha!

Wow, 10 years! I’ve got some ways to go.

Yeah, this:

is the same as:

But with fewer nodes. Essentially, this pin: