Rotating an object 45 degrees, plus & minus, in blueprint

Hi! Thanks in advance to anyone that can help.

As you can see below i have a blueprint attached to cylinder and i’m trying to press a button to rotate it 45 degrees on one angle but to rotate it -45 degrees on the same angle if another button is pressed (though i’m sorting it out so that the two cannot be pressed at the same time or during rotation, it’s very hacky atm).

i used this solution as a reference to what i’m trying to do How can I rotate an object over time when pressing a key? - Programming & Scripting - Epic Developer Community Forums but the issue is when i try to go activate Q rotation to rotate opposite E nothing happens. i’ve messed around with what i thought might be the issue, but nothing seems to get my object to rotate the opposite way by 45 degrees. if anyone has any suggestions (and improvement advice would be great too!) then i’d be all ears, though i must ask if you could explain your changes clearly as blueprint is new to me (and a bit alien) so stuff like custom functions go right over my head unless explained.

Thanks for your time!

Hello,

could you try 315 degrees rotation instead? If that works you might use some simple math nodes to always keep positive degrees :slight_smile:
(Like this: (WishedDegreePlusOrMinus + 360) % 360)

Would it be cheeky to ask what that may look like in blueprints, the system is rather new to me

Let’s first try to replace the -45 with 315, if that works I’ll show you a screenshot on how to do the math stuff :wink:

Ok so setting it to 315 makes the object rotate 315 degree’s counter clockwise, instead of -45 degrees clockwise, but it does do something, compared to setting degree’s to -45, which does nothing.

Yeah I thought about that, too, too late though.

The problem is probably the branch node, checking if degree is > 0. If degree is < 0, the rotation doesn’t get set, just remove that node and connect the event to the set degree node :slight_smile:

No need to make this complicated actually. Right click anywhere and click on “add timeline” this would create a special type of node that would play for a duration, that can loop and gradually affect values. WHen you double click it you will be greeted with the timeline. Click on the “f+” button to create a float value that’s changing over time. Shift+clicking creates points for this variable. You can then go back to the event graph and see that now your timeline has a float in put use this in combination with the execution pin to achieve what you want.

Cool this seems interesting, few questions though, do you mean by the f+ button to create a function that has a ticking float contained in it? could i not just use delta time? do you have any links to documentation on using the timeline node, it seems interesting but nothing in the realm of what i’ve used so far.

I see where your coming from, but removing it just causes the object to never stop rotating.

Ok! i got it partially working, i can rotate 45 degree’s on button press! and i can rotate back the opposite way using timeline reverse! new issue, i can’t rotate more than 45 degree counter clockwise, and ofc can’t rotate clockwise unless i’ve done the counter. here’s an image of what i did in blueprint

the level is a clyinder with 45 degree angles and i am trying to get it so i can rotate the level on button press either clockwise or counter clockwise so i need to set up the timeline to always rotate clockwise 45 degree’s with one button push and counter with the other. can timeline support this? will it be able to rotate 45 degrees again after playing a 45 degree rotation? as the main issue i’m having is it seems to reset on a new play button.

Create a second timeline instead of reversing the same one. You can duplicate the one you have right now and set the floats to negative.

Just make sure that starting one also stops the other one. You can use a sequence node for this and use the first execution pin to stop the other timeline and the second pin to play the new one from start. Playing from start is crucial for what you’re trying to achieve.