How to rotate object like in editor

Hello I want to rotate my cube with mouse like in editor

324933-1.gif

my blueprint

324934-33.png

All that’s visible here is “alt text”. No image.

To break down the problem, you’ll need to:

  • On Left-Mouse Button: get mouse position, convert from screen to world, and trace out to see what actors are under the mouse.
  • Store the actor somewhere as your ‘selected’ actor.
  • When an actor is selected, create a gizmo for it. I’ve not messed with creating gizmos, but I see there is some functionality available for them in UE4, plus there appear to be a few on the marketplace as well. Worst case, you could probably create one yourself made up of a few planes with transparent textures.
  • Then, on Left-Mouse Button: trace against specifically the gizmo (drag off the actor or component and look for LineTraceSingle). determine which axis you want to rotate along.
    • The gizmo may have separate components for each axis, so you can use the trace’s HitComponent to tell which axis component the mouse is over.
    • You could possibly determine it from the trace’s HitLocation relative to the hit actor, or from the ImpactNormal.
    • Not the best option, but you might could even use the hit PhysMaterial.
  • As long as the button is held down over the gizmo: on mouse movement, multiply the positive and negative movement along one or both mouse axes by a scalar (to adjust the ‘speed’ of rotation). That gives you a delta to apply to the Actor’s rotation axis. Then you can GetActorRotation, apply the delta to the desired axis, and SetActorRotation.

All that’s visible here is “alt text”. No image.
Better?
And thanks