User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: How can I use the mouse to rotate an object?

  1. #1
    Clicker Multimedia Fusion 2 DeveloperInstall Creator Pro

    Join Date
    May 2010
    Posts
    536
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I use the mouse to rotate an object?

    Hey, folks!

    I'm working on an Atari Asteroids style game where there is a spaceship which rotates and shoots bullets in straight direction from its action point. Presently I have the controls set up to only use left and right keyboard keys to rotate the spaceship. Is there a way I can use the mouse to rotate the ship's direction?

    Thank you for your help!



    Most appreciatively...

    RGBreality

  2. #2
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)Firefly 3D Module (Steam)
    Phi's Avatar
    Join Date
    Jan 2010
    Location
    England
    Posts
    1,964
    Mentioned
    25 Post(s)
    Tagged
    0 Thread(s)

    Re: How can I use the mouse to rotate an object?

    Advanced Direction Object has "Rotate towards an object" and might also have "Rotate towards a point". Custom coding wouldn't be too hard either if you know how to work the angles.

  3. #3
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Paul_Boland's Avatar
    Join Date
    Jun 2006
    Location
    Waterford, Ireland.
    Posts
    2,739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How can I use the mouse to rotate an object?

    Create two Active Objects, MouseCurrent and MousePrevious. In their properties, make both of them invisible so they are not show at the start of a level.

    In the Event Editor set up the following code...

    {Always position MouseCurrent where the mouse pointer is on the X axis.}

    Always
    > Set X of MouseCurrent to X of Mouse.

    {Calculate where MouseCurrent is in regards to MousePrevious on the X axis. Subtract the X of MouseCurrent from the X of MousePrevious which will return a number which is either positive (MouseCurrent is to the left of MousePrevious) or a negative (MouseCurrent is to the right of MousePrevious). If it returns 0, they are both in the same place, the mouse has not been moved. Store this value in Alterable Value A of MouseCurrent.}

    Always
    > Set Alterable Value A of MouseCurrent to X of MouseCurrent - X of Mouse Previous.

    {If MouseCurrent is to the left of MousePrevious, then every 0.05 seconds, rotate the SpaceShip 1 notice anticlockwise.}

    If Alterable Value A of MouseCurrent > 0
    + Every 0.05 seconds
    > Set direction of SpaceShip to direction of SpaceShip + 1

    {If MouseCurrent is to the right of MousePrevious, then every 0.05 seconds, rotate the SpaceShip 1 notice clockwise.}

    If Alterable Value A of MouseCurrent < 0
    + Every 0.05 seconds
    > Set direction of SpaceShip to direction of SpaceShip - 1

    {Always position MousePrevious over the mouse pointer, where MouseCurrent is, so the calculations are ready to be checked again.}

    Always
    > Set X of MousePrevious to X of Mouse.

    Off the top of my head, I think this should work. Might need a bit of tweeking but you should be able to rotate the SpaceShip by moving the mouse left and right.
    KnightTrek Productions
    http://www.knighttrek.com

  4. #4
    Clicker Multimedia Fusion 2SWF Export Module
    Jacob's Avatar
    Join Date
    Jul 2007
    Location
    Second pixel to the right
    Posts
    3,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How can I use the mouse to rotate an object?

    Or, if you want the spaceship to point at the mouse, set the angle of the spaceship to

    atan2(y("spaceship")-ymouse,xmouse-x("spaceship"))

    and then set direction to

    Angle("spaceship")/11.25

  5. #5
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Paul_Boland's Avatar
    Join Date
    Jun 2006
    Location
    Waterford, Ireland.
    Posts
    2,739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How can I use the mouse to rotate an object?

    Another way is to have an invisible object always at the mouse (just like my example above started) and always set the SpaceShip to look at 0,0 of the invisible object.

    WOW! So many ways to turn an object with a mouse .
    KnightTrek Productions
    http://www.knighttrek.com

  6. #6
    Clicker Multimedia Fusion 2 DeveloperInstall Creator Pro

    Join Date
    May 2010
    Posts
    536
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How can I use the mouse to rotate an object?

    Hey, Paul_Boland! Thank you for your suggestion! I really like how nicely that turns out! Great idea!

    But I need to pick your brain again... I need this spaceship to be able to turn 360 degrees (or all 32 directions). Because MouseCurrent only stays within the X-axis, the spaceship can only rotate 180 degrees (X-coordinates which are less than the spaceship's Y-coordinate).

    So, how can I adjust this so that the spaceship can rotate 360 degrees?

    Thank you again for your help and great idea!


    Most appreciatively...

    RGBreality

  7. #7
    Clicker Multimedia Fusion 2SWF Export Module
    Jacob's Avatar
    Join Date
    Jul 2007
    Location
    Second pixel to the right
    Posts
    3,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How can I use the mouse to rotate an object?

    Use mine, it solves for this

  8. #8
    Clicker Multimedia Fusion 2 DeveloperInstall Creator Pro

    Join Date
    May 2010
    Posts
    536
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How can I use the mouse to rotate an object?

    Hey, Jacob!

    I had tried your idea, but somehow the spaceship "snapped" (rather than rotated) to the mouse point. I wonder if I did it incorrectly? Here is what I did:

    1.) If "spaceship" is visible
    -->ATan2(YActionPoint( "Spaceship" )-YMouse, XMouse-XActionPoint( "Spaceship" ))
    --> Angle( "Spaceship" )/11.25


    I must have done something wrong, because the spaceship only moves within a 11.25 degree angle from its initial rotation.

    What did I do wrong here?

    Thank you again!



    Most appreciatively...

    RGBreality

  9. #9
    Clicker Multimedia Fusion 2SWF Export Module
    Jacob's Avatar
    Join Date
    Jul 2007
    Location
    Second pixel to the right
    Posts
    3,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How can I use the mouse to rotate an object?

    Set Angle to: ATan2(YActionPoint( "Spaceship" )-YMouse, XMouse-XActionPoint( "Spaceship" ))
    will set the angle in 360 degrees. The other part was just for setting the direction based on the angle.

  10. #10
    Clicker Multimedia Fusion 2 DeveloperInstall Creator Pro

    Join Date
    May 2010
    Posts
    536
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How can I use the mouse to rotate an object?

    Hey, Jacob!

    Ah, that totally makes sense! Great idea! Thank you much!

    Let me pick your brain one more time: After implementing this, I see that the ship can rotate very quickly (depending on how fast the mouse is moved). I've used the Kernel object to temporarily set the mouse speed to 2, and yet it moves really fast (sometimes just spinning around like a top)!

    Would you have any ideas on how to control the speed in which the ship rotates, regardless of how fast the mouse is moved?

    Thank you again!



    Most appreciatively...

    RGBreality

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Rotate toward object?
    By Outcast in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 5th July 2013, 02:53 PM
  2. Help Please... Need to Rotate Rotate object with a wheel
    By Tuna in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 12th February 2012, 04:48 PM
  3. 360 rotate object
    By Evilized79 in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 19th July 2011, 07:38 PM
  4. Rotate towards and shortest rotate direction
    By Tiles in forum File Archive
    Replies: 19
    Last Post: 2nd October 2010, 02:25 PM
  5. Rotate at object
    By jellytot in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 2nd January 2007, 06:55 PM

Posting Permissions

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