Rotating object to follow mouse

Okay, say I have an object (a bee in this case) that I want
to follow the
mouse around, that part's easy:
property my,oldLoc
on beginSprite me
my = sprite(me.spriteNum)
oldLoc = my.loc
end
on exitFrame me
my.loc = the mouseLoc
if diff(my.locV,oldLoc.locV) + diff(my.locH,oldLoc.locH)
> 5 then
my.member = "BeeBuzz"
else my.member = "BeeStill"
oldLoc = my.loc
end
It even includes a cute little function to make the wings
buzz when it's
moving, and not when it's standing still. The tricky part is
I want to have
some way of making the bee rotate to move in the direction
the mouse moves.
This seems to *almost* work, except that when the locV
doesn't change, it
results in a divide-by-zero error:
my.rotation = atan((oldLoc.locH - my.locH) / (oldLoc.locV -
my.locV)) *
57.2958
I could check and artificially add a small amount to avoid
the
divide-by-zero, but that seems like a hash. Is there a better
way to do
this correctly?
(And does anybody mind if I rant a bit about how all rotation
properties in
the program operate in degrees, while all the trig functions
operate in
radians? And the program doesn't include a method to convert
between them
either. That's just annoying.)

Thanks. I generally try to avoid the Library behaviors
because I've found
that they mostly seem to be 98% unnecessary error-checking
and 2% functional
code, and it can often be very difficult to find and extract
that tiny
little bit of code that actually DOES anything. However, in
this case I was
able to pull a bit of useful code out of the Turn Towards
Mouse behavior -
extremely simplified of course. It didn't work at all out of
the box. For
the record, the code I used looks like this:
angle = GetAngle(oldLoc - my.loc) - 90
if my.rotation <> angle then my.rotation = angle
With the following code copied (mostly verbatim, but
simplified) from the
Turn Towards Mouse:
on GetAngle slope
deltaH = slope[1]
deltaV = slope[2]
if deltaH then
slope = float (deltaV) / deltaH
angle = atan (slope)
if deltaH < 0 then angle = angle + pi
else
if deltaV > 0 then angle = pi / 2
else if deltaV < 0 then angle = (3 * pi) / 2
else angle = 0
end if
return (angle * 180) / pi
end GetAngle
It seems to do pretty much what my original code did, only it
considers
those divide-by-zero situations separately as special cases.
Still seems
like more code than should be necessary to do what it does -
this feels like
the sort of thing that should be possible with 1-2 lines of
code, but
apparently it's not that simple...

Similar Messages

  • Noob question, can't rotate object clockwise. Please see the pictures below.

    Hello everybody!
    I'm stuck at rotating objects as I tried to follow a tutorial.
    I think the answer is very simple, but because of my weak English, i can't even figure it out how to search for it on Google. tio
    So my question is how to rotate objects like this:
    Instead of this (That's how i can only rotate this object.):
    Thanks in advance!

    zollre,
    - before the value gives you clockwise. Basically, rotate angles are counterclockwise (with an implied + before the value).
    -20 degrees corresponds to 340 degrees (almost a full round counterclockwise).

  • Ugh!  Please restore old Terminal.app focus-follows-mouse behavior!

    The 10.4 and prior Terminal.app's focus-follows-mouse feature allowed one to type into the terminal by mousing over it even if the Terminal wasn't the currently focussed application. It didn't focus Terminal when you did this, but did direct keyboard input to it.
    10.5's Terminal.app only allows focus follows mouse to work when it's the focussed application, which destroys about 80% of this feature's usability for me. I like to keep things like finder and browser windows overlapping most of a terminal window and then just slide the mouse over to the terminal to type there, and I can no longer do that in 10.5. Now I have to click on the Terminal window, bringing all my terminal windows forward and obscuring the windows I wanted on top. Very annoying.
    Is there any way to restore the old behaviour? If not, can we please have it back?
    Luckily, 10.4's Terminal.app still behaves properly in 10.5, so I'm using it, but I'd like to have some of the new features of 10.5's Terminal.app. Unfortunately, "broken" focus-follows-mouse is a deal-breaker for me.

    The command I know,
    defaults write com.apple.Terminal FocusFollowsMouse -string Yes
    seems to work about the same in Leopard as in Tiger for me. I don't remember ever being able to get focus-follows-mouse behaviour to work in a non-active application from an active non-focus-follows-mouse application. In other words one can focus follows mouse from one Terminal to another, but not from Finder to Terminal.
    The X11 equivalent (why the inconsistent key and value?) is
    defaults write com.apple.X11 wm_ffm -bool true
    I remember being able to focus-follows-mouse between Terminal and X11, but cannot in Leopard. However, I also cannot in Tiger 10.4.11 either, so maybe it is my memory that is faulty.
    What I don't seem to be able to do, but could do in Tiger, is
    defaults write com.apple.X11 swapaltmeta -int 1
    On Tiger, that would make the option key the meta key, so that e.g. alt-d would delete forward one word, etc. On Leopard, this seems to be a NOP which means that cmd is the only possible meta key, which I personally find rather confusing.

  • How to always rotate objects around the same point, even using the right-click menu?

    I need some of my objects to always rotate around the same point. How can I select a point which will stay that way?
    Using the rotate tool resets after deselecting.
    Also, I'd like to rotate objects around a certain point even when using the right click > Transform > Rotate.
    Is it possible?

    Right, so this is where Illustrator falls short with respect you your need, but only in the sense that the reference point can't be made to stick. You can, however, use Smart Guides to make it so the point is easy to set at exactly the same location, (especially since your object has an anchor point there), manually before each rotation.

  • Rotating objects in a table

    I have dropped an object (picture) into a pages document. Then I rotated it with 90°. When I copy or drop the picture into the cell of a table, it is rotated back into the original orientation and I cannot rotate it any more.
    Is there a possibility to rotate objects in table cells?

    The only way I can find to do it actually doesn't insert the graphic in the table per se. It's a workaround that may or may not suit your purposes. FWIW:
    1. Click outside the margin and insert a shape (square) as Fixed on Page and in the Wrap Inspector deselect Object Causes Wrap.
    2. Drag it over the cell you want the picture in and size it to fit the cell.
    3. In the Graphic Inspector's drop down Fill menu, choose Image Fill and choose your picture (rotated as you want it). In the drop down menu below the Fill menu, select either Scale to Fit or Scale to Fill, as necessary.
    4. When you have the picture situated as you want it, click on the picture and shift click on the table and from the Arrange menu select Group.
    At this point you can set it for Moves With text if that is what you need, or leave it as Fixed on Page and position it where you want it.
    Hope this helps.
    Walt

  • Rotating a circle using mouse coords.

    I'm trying to rotate a circle. I want the circle to rotate in
    relation to the mouse movement across the y axis. Here is my code
    so far:
    onClipEvent (enterFrame) {
    _root.xVal = Math.round(_root._xmouse-this._x);
    _root.xMove = Math.round(_root.xVal/10);
    this._x += _root.xMove;
    _root.circle._rotation += _root.xMove*.4;
    And here is the swf so far:
    HERE
    As you can see, this is the idea i am getting at. I would
    like the globe to rotate CW when the mouse is moved to the right of
    the globe and CCW when the mouse is moved to the left of the globe.
    I would also like the globe to slow as it comes closer to the
    mouse, but faster as the mouse is further away.. similar to the box
    that moves above the globe.
    When the mouse is put on the globe i woul like it to come to
    a stop slowly so that the user can select something. If anyone has
    any ideas please help.
    Much appreciated,
    Thanks.

    hello,
    i have seen your swf and i think you want the blocks on your
    circle to be menubuttons if i'm right?
    I would use back and next buttons to turn the button circle.
    This because your mouse must be at your button.. and if you
    move your mouse to the right or left to see the next button you can
    never click the button thats on top at that time.
    what you CAN do is make a rotationbar like your block.. and
    if your mouse is on the rotationblock the circle rotates.(like you
    did now)
    if you get your mouse off the block the rotiation stops and
    the button you want to see is on top.
    so the only difference is that you need the mouse to be at a
    predeclared area for rotation.
    Greetz, jacob

  • Is it possible to create a rotating object in Muse?

    Is it possible to create a rotating object in Muse? I have a round logo and I want it rotating.

    HI
    If you are looking for an animated logo, which rotates in 360 degree, it is not possible in Muse. You can create an animation in Edge animate and import the animation in Adobe muse.,

  • Rotate view tool over mouse center?

    Hello all!
    As the subject states - is there a way to use rotate view tool so that it's center of rotation is on the mouse / cursor location?
    I have tried different key command combinations and no go. If this is not possible at this point, then I would love to have that as a feature! It would be SO much more efficient and much less frustrating.
    I hate having the rotation center in the center of the window rather than where I am painting. Now, if there is an option to do this somewhere then please disregard my rant.
    Thanks
    Ray

    No, I don't mean that you wouldn't be using a mouse to do so- of course, you would be using the mouse. I am just simply saying that when you rotate the image using the rotate view tool, it doesn't spin the canvas around the point of the mouse, it spin's it as you said around the image window's center. That's all I'm saying.
    To me it would be much faster if it were to have an option to spin around the mouse's center because, as I mentioned before, try working on a zoomed in corner of your image and then when zoomed in and in that corner of the document, use the rotate view tool, because you want to get a better angle for painting in that corner area of the zoomed in image. Spin the image 45 deg and see what happens.
    The area you were just working on is now totally out of view and you either zoom out to find the area again and pan back to center that location and zoom back in to continue working on it or pan around to find and center it again. Either way, that stinks in comparison to just rotate the view based on either your last mouse click or where you mouse is at the moment.
    Do you understand?

  • Adobe Creative Suite CS5 is acting up. In Illustrator i was unable to move objects with my mouse, so

    Adobe Creative Suite CS5 is acting up. In Illustrator i was unable to move objects with my mouse and tried solving the problem in different ways - it still didnt work. So i opened up photoshop. I was unable to open a file in photoshop (new or old) and when i finally did manage to open something, I am unable to do many things.
    1) i cannot crop canvas    
    2) i cannot resize canvas
    3) text dissapears after i type it
    4) brush strokes dissapear after i release mouse
    etc
    What should i do??
    Thank you!

    Nobody can help you without system info or otehr details. From your description this could be driver issues with a tablet if you use one or similar issues with a programmable custom mouse... Most definitely not an issue within the programs. Unplug your mouse and tablet, uninstall and reinstall the drivers, try another input device...
    Mylenium

  • A program that can rotate objects

    Is there any done program that can rotate objects from graph?
    I am not a programmer I just need to use that for mathematics.
    Any help will be appreciated.

    I'm not sure what you are asking for. You can rotate an image with [url http://java.sun.com/j2se/1.4.2/docs/api/java/awt/geom/AffineTransform.html]AffineTransform. You can look at the source for it in src.zip. You can [url http://onesearch.sun.com/search/developers/index.jsp?col=devforums&qp_name=Algorithms&qp=forum%3A426&qt=rotate]search for algorithms.

  • Xmonad and focus follows mouse issue

    I've been fiddling around with xmonad, and I notice that with focus follows mouse turned on, when I create a new window the window under the mouse gets selected instead of the window that I have just created. Pretty irritating, Anyone know how to solve that?
    Thanks for any help provided,
    Kruppe

    Yes, disabling the focus follows mouse behaviour makes it so the correct window is always chosen.
    I kind of like having focus follows mouse for when I need to copy and paste in applications that don't provide good methods for doing that purely with the keyboard (firefox and most terminals when not using screen). I would therefore like to have focus follows mouse.
    Sidenote: What is this updatePointer thing you use and what does it do?

  • CAN IT BE DONE??? Object to Follow Path in CS3??

    I'm working with CS3 and came across this perdicument!
    Does Anyone know how to get an object to follow a custom shape path?? Is this possible in CS3?
    Thank you for your replies!

    It sounds like you want to use Corel's Painter instead for this as it has a <br />special brush called an Image Hose which allows you to load an image or <br />images and sprays them along the brush path as you paint.<br /><br />http://apps.corel.com/painterix/training/tip_image_hose.html?trkid=tpc0705tip2<br /><br />If this is a one off job you can download a free trial.<br /><br /><br />"kimberlyrae" <[email protected]> wrote in message <br />news:[email protected]..<br />> I'm working with CS3 and came across this perdicument!<br />> Does Anyone know how to get an object to follow a custom shape path?? Is <br />> this possible in CS3?<br />> Thank you for your replies!<br />>

  • Focus follows mouse

    Hi,
    Is there a way to keep a window open while another window is selected? What I would like to is manually type in a window while another window is visible. Other than clicking on alternate windows or resizing the windows I know of no way to do this.
    It seems to me that I had a utility that had focus follows mouse as one of the options. This stopped working a couple of releases ago and I have forgotten its name.
    Thanks.

    I can't appreciate the small space since I don't have a laptop, but you should be able to squeeze in two, either side by side or one on top of the other. Increase the display resolution, maybe? Other than that, I feel thy pain.

  • Focus follows mouse, etc

    So many years ago I was a mac user. And many years ago this forum looked different...
    But I have since switched to linux. Which I like because I can program it however I want.
    BUT now I have a mac again. My macbook with intel ran linux, but it died. So now I have a powerbook. Since PPC linux ***** I'm running 10.5 on it.
    I actually really like this system. It's pretty straight forward and easy to use, just a few things I want for it that I can't find.
    One big major thing that's really holding me back with the system is there's no focus follows mouse. Especially with the small screen it's something I really need to use the computer. And no auto-raise please. That completely ruins the point of focus follows mouse.
    I do have it working in terminal via playing with some plist files. And that's mostly where I use it. But I use it enough on the rest of the system that it's something I really want.
    Also, I'd really like to be able to hold down a modifier key, and click anywhere in a window to be able to move it. Something else I've become really accgstomed to in my GUI that I'd like to have on this little machine.
    Thanks for any help.

    Cool! Thanks for Window Wrangler! That's a pretty neat program. Not what I was looking for exactly, but it'll do just fine.
    I now see what you were trying to show me with the zoom. That's not what I'm looking for.
    What I'm looking for is focus follows mouse. What it does is as you put a mouse over a window, that window gets focus. But does not raise to the top.
    So say I have a web browser open, and my IM client open. I'll leave the client at the bottom of the screen and have the browser sized up just enough to see the text field and the first two lines of conversation of the chat.
    Now, on my linux system to reply all I have to do is put the curser over the IM window and I can type into it without having to click on it and bring it to the top.
    For that example, it isn't a huge deal. But when you have 5 or 6 windows open all organized with each on the right level, bringing one to the top will screw it up.
    I'm liable to have a few terminal windows, IM, email, IM, some programming ide, etc open at once. It's especially useful for web development. I can have the source file open and edit it, but not bring it over the browser window so I can have an idea of what I'm doing with the source.

  • Focus Follows Mouse In Aqua (No, I don't mean X11)

    Hello mass of Apple users!
    I have been switching back in forth between my Windows XP install and OS 10.4.11 and realized how much I miss focus follows mouse.
    Does any one know how to enable it? From what I've found it doesn't seem
    to be possible, except with the Terminal application, which can be enabled with by using defaults.

    MondoMouse - VersionTracker or MacUpdate.

Maybe you are looking for

  • Consingment settlement

    hi gurus, i can see the doc i created in mrko but in info text it is written ¨¨not settled¨¨ thus i cant save the doc. reply soon please its urgent.. thanks. piyush singh

  • Payment Term -- From where it is getting defaulted

    hi, i want to default the payment term from customer in AR to order management while creating the order? i want some one in this forum to explain the sequence of payment term getting defaulted, i see the payment term defined in release r12 in many pl

  • REG : Sender FCC

    Hi All,          I have a scenario where my source file is a flat file.I am using a FCC at sender side to convert the flat file into XML. My source side looks somting like this: Root     Header     Data     Footer. Header and footer will repeat only

  • Component Panel ( Design mode) loosing custom components

    Wonder if anyone else encounter this phenomenon? After placing custom Flash components ( compiled intoa SWC file) in the project's <Libs> directory, they are available and working in Source mode, but you can't see them in the custom Folder (In the De

  • Steps for creating a database index

    Do we just create it from SE11? Does Basis needs to be involved for any furthur steps?