x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

keep a button pressed to rotate an object

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.

Product Version: UE 4.21
Tags:
more ▼

asked Dec 05 '18 at 07:25 AM in Blueprint Scripting

avatar image

IvayloEGT
5 2 5

avatar image aNorthStar Dec 05 '18 at 07:51 AM

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)

avatar image IvayloEGT Dec 05 '18 at 07:55 AM

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

avatar image aNorthStar Dec 05 '18 at 08:09 AM

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

avatar image Tuerer Dec 05 '18 at 08:15 AM

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.

avatar image aNorthStar Dec 05 '18 at 08:17 AM

thank you Tuerer, I didn't know Axis input ran off Tick...

avatar image IvayloEGT Dec 05 '18 at 08:25 AM

Neat, i will try it now!

avatar image IvayloEGT Dec 05 '18 at 08:36 AM

ok, this is almost working :D 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 :D

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

alt text

unreal.png (147.3 kB)
avatar image Tuerer Dec 05 '18 at 08:42 AM

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.
alt text

brmc-6.jpg (119.4 kB)
avatar image IvayloEGT Dec 05 '18 at 08:52 AM

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 alt text

unreal1.png (82.7 kB)
avatar image Tuerer Dec 05 '18 at 09:00 AM

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.

avatar image IvayloEGT Dec 05 '18 at 09:03 AM

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?

avatar image Tuerer Dec 05 '18 at 09:19 AM

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.

avatar image IvayloEGT Dec 05 '18 at 09:21 AM

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.

avatar image Tuerer Dec 05 '18 at 06:49 PM

Ok, here it is, as promised.alt text
A simple timeline that goes from 0 to 1 in 1 second. As for the blueprint: alt text
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.

rot1.png (21.6 kB)
rot2.png (151.3 kB)
avatar image IvayloEGT Dec 06 '18 at 12:56 PM

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 ?

avatar image Tuerer Dec 06 '18 at 01:01 PM

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.

avatar image IvayloEGT Dec 06 '18 at 01:34 PM

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

avatar image IvayloEGT Dec 05 '18 at 10:55 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Dec 05 '18 at 07:48 AM

avatar image

Tuerer
1.8k 12 7 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question