Drag to rotate an object.
hi,
This is my first post here.I am using a demo version of MMF2 and have found the posted tutorials a great help.
Now I have a question regarding dragging and rotating an object. Is it possible to drag and rotate an object about its hotspot? I mean is it possible to click on an object(a circle to be exact) and while the mouse button is pressed, the object rotates about its centre? When the mouse button is not pressed, the object stops.
Re: Drag to rotate an object.
Hello. That's very easy to do There's an action "Set angle" in "Scale / Angle". You can also get the angle in the expression menu.
Do something like
Set angle to Angle("Active")+5
to rotate it continuously.
Re: Drag to rotate an object.
Thank you so much for taking the time to answer my question. :)
But I sort of already could do this. My specific problem is to sort of create the illusion that when the player presses the mouse button down and moves the button on the object, it appers as if the mouse is slowly rotating the object by dragging it around the centre.
I really hope this can be done. And thanks again for answering my question.
Re: Drag to rotate an object.
You can set the angle depending on the mouse position:
ATan(XMouse-X("Active"), YMouse-Y("Active"))
(I hope it's ATan - it's the arc tangent expression)
Re: Drag to rotate an object.
Ah, yes, I was unsure if it's that what you wanted.
I'm going to extend Czentnar's code here - his would always reset the angle to 0 before rotating.
While the mouse is not pressed,
Set alterable value A to Angle("Active")
While the mouse is pressed,
Set the angle to Alterable value A("Active")+ATan2(XMouse-X("Active"), YMouse-Y("Active"))
It's Atan2. :)
Re: Drag to rotate an object.
Yes, it's ATan2... thanks Looki, your code is better! :)
Re: Drag to rotate an object.
Thank you so much guys. Looki and Czentnar, you are absolutely awesome and very generous. :grin: :grin: :grin:
Re: Drag to rotate an object.
You know, I spent a good hour yesterday trying to make one that did not reset the angle. I KNOW I tried that exact setup (plus many many others) but it never worked. :S
Ah well, I probably missed something. XD Thanks for the info, Looki!
Re: Drag to rotate an object.
Hey guys,
Its me again.Ran into another problem.
I followed the instrustion the way it is posted here and it works beautifully except for a little problem.Everytime the player clicks on the object to rotate it, it sort of jumps forwards a few degrees and then starts to rotate.
Is there a solution to this?
Thanks in advance.
Re: Drag to rotate an object.
Hey. Not sure - maybe you set the alterable value after setting the angle? Try swapping the event order!