keep a button pressed to rotate an object

here is some pseudo code that might help

… place a Trigger Volume to cover your room

On press Q
… Branch true when Player Character is inside room
… add/deduct world rotation to display actor

On press A
… Branch true when Player Character is inside room
… add/deduct world rotation to display actor

If you’d like it to rotate by discrete amounts (add some DoOnce and FlipFlop logic linked to button press and release)

hello, im doing a “virtual showroom” and i have a machine i want the player to be able to rotate. I have a player who can walk around. I have a always facing the camera text with the button prompts. Now i want to Press Q and E to rotate the object i have in the middle of the room in each direction. but only to rotate when the button is pressed. when release the rotation must stop. I tried a couple of variants but to no avail. I tried with a timeline but it executes some degrees rotation on each press. Not by holding it.

I forgot to mention i am quite new at this so i appreciate your answers but can you give me a little bit more information because i am not sure how to link the nodes and all the nodes which i need to use.

Also my button input should be Axis not action right?

I have the collision box and the input works only when im inside… at least i got this working.

Thanks in advance

Neat, i will try it now!

ok, this is almost working :smiley: when i press Q it starts rotating at 25 degrees per second … but it does not rotate while i hold the key, it just starts a continuos rotation, and everytime i press Q again it adds to the speed. After 10 presses its like a astronaut test :smiley:

So how do i make it to rotate only while holding the Q ?

yes, I’d say it’s best to use Axis

as a beginner, your biggest challenge might be getting a reference to the Display Actor, in order to rotate it. So, for simplicity, using Begin Play in your Player Character BP, I’d spawn the Display Actor at the desired vector location). Then you can easily get a reference to it, and plug that reference into your Add Actor Rotation along with your Q and A axis inputs.

alternatively, to quickly get a reference… you might use Get All Actors of Class, drag out an array and get the first item (item 0)… (this approach assumes you only have one of these Display Actors in your level)

Neither approach is super-efficient or ideal, but they will get you started quickly

I wouldn’t recommend using Axis input for that; Axis works on Tick, so if you create a certain formula for rotation speed based on Axis, this speed may be different on different computers. Let’s say, you have 120 fps, and you rotate your object by 0.5 degrees every tick, so it will rotate by 60 degrees per second. Then you give your project to your friend whose computer is not as powerful, and he has 60 fps, and in his case the rotation will be 30 degress per second.


Whereas a Rotating Movement component uses real time to calcullate rotation. So if you set it to rotate 60 degress per second, it will rotate 60 degrees regardless the frame rate.


So, all you have to do is create a bluepring with your object, add a Rotating Movement component, set initial rate to 0,0,0; Then, when you press a key (Action, not Axis), you get the object’s Rotating Movement component and set its rate to 0,0,X, where X is the number of degress it will rotate per second. When you release the key, you set the rate back to 0,0,0.


Unfortunately I can’t provide you with any screenshot now, I don’t have access to the Engine at the moment.

thank you Tuerer, I didn’t know Axis input ran off Tick…

You should add a Rotating Movement component manually before starting the game (in the top left corner of your blueprint window where all the components are). Then you get that Rotating Movement component into the graph, drag the output pin and find Set Rate. There you can set the rotation rate by key press.

If you select the Rotating Movement component in the BP, you’ll see in the details that its rotation rate is set to 0,0,180. Just set it to 0,0,0.

You can use a timeline for that. It’s quite easy as well.

But explaining it in text would be quite cumbersome, I can provide you with some screenshots, but only in about 7 hours, when I get home from work.

Okay!! we are almost there. Now when i start the game the machine rotates fast and when i get near to it and press Q it starts rotating slowly with the rate i gave it in blueprints. And it rotates with the correct speed WHILE i am holding the button. And it stops rotating at all when i release !! Only thing needed to be fixed is why its rotating fast from the start of the game ? THank you so much

Alright, that did it. I cant believe how many complicated answers there are in the forums and everywhere i searched the last 2 days … and it turns out to be so simple.

If its not too much of a bother would you know if we can take this one step further? for example that rotation to be smooth as in to start slowly to build up to the RATE i had given it and to stop smootly when i release the button?

Also i cant seem to resolve this topic as it says there are 0 answers?

whenver you can, it is not urgent and because the rotation is working i can go on to the next things in my project. Thank you very much.

@Tuerer if you could convert some of your comments to answers so i can mark it as resolved ?

You can add a Rotating Movement component to an actor (it has to be a blueprint, even if there is no other functionality), and on key press you set the rotation rate to the needed value, and on key release — to zero.

Ok, here it is, as promised.


A simple timeline that goes from 0 to 1 in 1 second. As for the blueprint:


Those "Rotate left/Right" and Branches are basically your Q and E pressed and released. Upon pressing any of them, set Rate to whatever you need, positive and negative, this way you can use the same timeline for both directions. And you can use Lerp instead of Ease, but I personally prefer Ease for it provides a bit more control. You can select various functions to get the result you'll like better.
1 Like

Thank you very much for the additional info! I am now occupied trying to package a beta version of my project and am having so many problems but am resolving them one by one.

Hopefully last question for the topic at hand. When i am keeping the button pressed and walk backwards and exit the box collision overlap area, the engine interprets this as if the button stays pressed and it will rotate continuously . Is there a way we can tell it to stop rotating when im out of the box ?

Create a Custom Event in the exhibit BP and connect it to the Reverse input pin of the timeline. Then in the Level BP, create an On End Overlap event for the Box Collision, which will call that function in the exhibit BP that you created.

awesome, will try it soon. You should write tutorials :smiley: