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!
Re: Drag to rotate an object.
That's the problem that I had. >_>
Re: Drag to rotate an object.
Oh, I see.
Use this as expression instead.
Alterable Value A( "Active" )+ATan2(XMouse-X( "Active" ), YMouse-Y( "Active" ))-90
Re: Drag to rotate an object.
Thanks for your quick reply. :)
I followed your instructions to the letter, but the problem persists. :confused:
Re: Drag to rotate an object.
Try this. http://clickteam.info/looki/Examples/RotateObj.mfa
Re: Drag to rotate an object.
Thanks Looki for posting the file. But I still have the problem. Is anyone here who might have had the same problem? Or is it just me?
Re: Drag to rotate an object.
I can confirm the problem, if you keep clicking, it will keep moving around even though you don't move the mouse.
-Build 248, MMF2 Dev.
Re: Drag to rotate an object.
Re: Drag to rotate an object.
Thanks guys for trying out this problem for me. i noticed something this time around. when I click on the object, it jumps around as we all know. But if i click on the exact same spot again, the object doesn't move. I don;t know what to make of this.
Re: Drag to rotate an object.
I noticed this also, my guess is that it's to do with the way the set angle events were set up because it seems to snap to the mouse angle rather than the objects previous plus the new angle.
To fix it so it doesn't automatically move when clicking off the active you would set up a is over event also and set a value then on release clear that. That way it only would rotate after clicking and dragging around rather than clicking and it jumps to the angle.
To make it more stable it would need a limiting for when you click outside of the object area holding the mouse and dragging it back over again. If your not sure what i mean by this i made basically this for the hold button in these widgets i made a while back.
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=115836#Post1158 36
Re: Drag to rotate an object.
Thanks Atom for pointing me to your widget. Unfortunately, I still can't make it work.
I feel really stupid and this is diving me crazy. :blush:
Re: Drag to rotate an object.
No, for me if I keep clicking in the same spot it will keep turning. :o So there must be somthing strange going on here...
Re: Drag to rotate an object.
Proy, I made an example for you:
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=154050#Post1540 50