Issue with rotating an object in increments - player controlled

Hi there,
I’m currently having trouble implementing a game mechanic in my game prototype. I want to rotate an object in the game through player input, but rather than it being a simple animation through matinee I want it to be the core mechanic allowing the player to rotate this object at any point during the game along any of the axis.

Currently, I am working on a simple pyramid object to get the mechanic working. I want it to rotate at 90 degree increments by any axis, one at a time. This will be done via player input, for example: Pressing up once to rotate it 90 degrees through pitch. I want it to be able to go in any direction at any time. Only ever in set intervals of 90 degrees, not free flowing.

Currently, I have a blueprint that makes the object rotate by 90 degrees along Pitch. It works fine at first but then changes direction when it shouldn’t do. I want it to keep rotating in a continuous direction, not come back on itself.

Here is a GIF of the current problem.

Hello DanSaxon,

I recreated your blueprint to see if I was able to reproduce the outcome you were experiencing which was indeed the case. I tried tweaking your set up a bit to test out different outcomes all with different and varying results. I was almost able to get it to work with the “Move Component To” node, but as soon as I went from 180 degrees to 270 degrees the mesh did some twisting and turning and re-positioned itself instead of a clean rotation of pitch. This is something I will look into further because it seemed to only happen with Pitch, and not the Yaw or the Roll factor.

That being said, I was able to get the correct outcome of what you are looking for (hopefully) by adding a couple of nodes in the construction script and changing up the logic a bit. We still are using a Timeline and Lerp in between a rotation variable we create and a float vector. Follow the instructions given and use the images on this post as reference on how to set up your blueprint correctly.

Steps to Follow:

  1. Open your current Actor blueprint, or create a new one.
  2. Assign a Static Mesh in your components tab to your blueprint. In your case whatever you are attempting to rotate.
  3. Go into your ‘Event Graph’ and click on the ‘Construction Script’ tab.
  4. Use the image provided to Set up your blueprint logic. You will need to create a Rotator variable and label it whatever you would like. Something that makes sense like, ‘Rotation’.
  5. Now go into your ‘Event Graph’ and use the second image as your reference how to set up your Blueprint on a key press.
  6. Keep in mind my ‘Timeline’ is a linear zero to one time frame.

Construction Script

Event Graph

After getting everything connected, double check to make sure it matches the images and press play. Hopefully when you press the key you have assigned to the rotation, it gives you the desired effect. Keep in mind if you mash the input key it will continually reset the rotation position until it has completed its rotation.

I hope this helps clarify some of the questions you had and gets you on the right path!

Cheers,

Hey! Know it’s been over a year, but you have exactly what I need and can’t find it anywhere… What does your timeline look like to allow that smooth movement of the pyramid? Mine currently just snaps from 90° and I’d like it to smoothly rotate! Please do let me know!

Hey Invisible,

Perhaps the below image can help. Since you are incrementing, you will want to Play from Start, and set the rotation to be over a 0 to 1 change. 0 representing the start of the rotation, and 1 representing the finished rotation. This will be a linear line from 0 to 1 over X amount of seconds.

Incremented Rotation along Timeline

Let me know if you have further questions.

Thanks,