Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 6 of 6

Thread: can someone help me on how to make a movieclip rotate to the position of your mouse?

  1. #1

    can someone help me on how to make a movieclip rotate to the position of your mouse?

    It'll probably seem simple to guru's but it's like looking at a blank wall for me :S,
    could you help me with finding the formula to determine the rotation for the movieclip ?
    (a gun in this case, along with the arm), since the rotation will determine the path of the bullet it fired.

    My guess it has something to do with radials, but that's just a guess

    Thank you a lot in advance

  2. #2
    Here in Kirupa, at the 3D Flash tutorials they have a short page on the basic trigonometry knowledge you'll need for this and many other features:


    It's worth looking.+
    Bruno Palermo
    When everything is catastrophic, thank the Gods things aren't worse!

  3. #3

    Ooooh, now i see, thank ye :) i allmost forget what i learned a couple of years ago

    Thanks for the url , it has really helped me a lot

    So i can be pretty damn sure the code has to go something along these lines

    The one thing that bugged me the most was how to find out the radius after reading what you sent me, but i found out that to determine the actual radius of the arm mount point compared to the mouse position, that it had to be something like this

    radius = Math.sqrt((_xmouse - arm._x)*(_xmouse - arm._x) +(_ymouse-arm._y)*(_ymouse-arm._y))

    And building on that this formula i could derive=>

    arm._rotation = Math.PI(Math.atan2((_ymouse-arm._y), (_xmouse - arm._x)))*2

    I'll try it out now

  4. #4


    function focus(obj,xm,ym)
     obj.rot = -Math.atan2((obj._y - ym ),(xm - obj._x ))*180/Math.PI;
     obj._rotation = obj.rot;
    xm, my PLACE where u want obj to rotate to.

  5. #5

    i think i made a mistake in reasoning somewhere :S

    oo Thanks suvenier

    (i made a mistake on my own, and posted this before reading the post of ye, hence the edit)

  6. #6

    It works perfectly

    Not a single flaw, i owe you one suvenier

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012