This was not my first port of call. I’ve spent the last few days browsing countless posts with the same general idea.
What I am trying to achieve is simple. I want to rotate an object (A cube, possibly with other objects attached but I think I can do that and group them some how… I’ll get to that later though), by clicking and dragging. The real goal is to use touch to do it but for debug purposes and the fact that its not a difficult task to change, the mouse will do. I want to be able to click, and drag quickly and when I let go, I want the object to slow down and stop rotating. The camera remains stationary.
One of the problems I seem to be having with the things I find online is that if I try to paste in the code, Unreal crashes. Also, I don’t know whether to put it in the Object blueprint (Select the object, click add blueprint) or the level blueprint and often when attempting to attach a Target node, the cube target isn’t present and I can only “Cast to cube”.
These are my main problems. How would I do this in a blueprint form?
Well, I have a stationary floating camera, pointing down towards the cube on an angle. When I am looking through that camera (which is always), I wan’t to be able to click and drag (Preferrably with touch) and have the cube rotate around its center point. I only need rotation on 2 axis. The up down axis and the left right axis, no need to twist. (Like moving a sim’s head around or a minecraft character’s head).
When its working, I should be able to click play, and then click and drag/touch and drag the cube around it’s center point. (Rotating on the spot).
Here is a little video, how to set up the pawn itself and the game mechanic. The cube is nested inside the player pawn. If you want to use objects outside of the player pawn, you could simply use a line trace and get the reference and then use the add local rotation on the hit object from a linetrace :).
You need to toy around with this system a bit, because I don’t know, how you want to have it working in the end. This might just be a nudge into the right direction :).
So, that is almost perfect! Thank you so much . I added an Invert Rotator so click drag left rotates the cube to the left. One small problem, when the cube is flipped vertically, the horizontal controls are wrong and they become inverted. I thought about adding a Branch but the best way to do it would be relative. I gave addRelativeRotation a chance but to no avail. Any help is greatly appreciated! Thanks!
I will look into it eventually, when I get time for it :). I used the add local rotation, to avoid gimbal lock (3 axis occupy the same space, so flipping of the target object occurs). I think the system just needs some kind of reference point.
EDIT: Try this: You might need to invert your rotators again, but it keeps your axis direction consistent.
Create a null object like a sphere next to your cube mesh in your blueprint class actor. (cube and sphere are equal levels) Upon mouse down, PARENT the cube UNDER the Sphere… Rotate the sphere (not the cube). Upon mouse UP - UNPARENT cube… RESET rotations on Sphere back to 0,0,0.
What this does is resets the sphere everytime you let go of the mouse button. So, no matter what orientation the cube is in, it will rotate correctly (left makes it go left, etc). Hope that helps.