User Tag List

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

Thread: Rotating Objects Towards the Mouse

  1. #1
    No Products Registered

    Join Date
    Aug 2006
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rotating Objects Towards the Mouse

    Hi,

    I'm trying to make an object point towards the mouse using the Angle option in the Events Menu.

    I thought I would be able to find the angle between the object and the mouse using Trigonometry (tan)

    This is how I thought I would be able to do it:

    Set Alterable Value X to... Mouse X - X ("Object")
    Set Alterable Value Y to... Y ("Object") - Mouse Y (because Y axis is inverted)

    Then using the fact that:

    Angle = tan^-1 (Opposite/Adjacent) or
    Angle = tan^-1 (Alt Value Y/Alt value

    I set Alterable value Z to... Alt Value Y/Alt Value X

    Then finally set the Angle of the object to:

    ATan(AlterableValueZ("Object")

    Well... if you followed any of this... it didnt work and seemed to limit the angles to either:

    0 degrees, 45 degrees, and then most angles between 80 and 90 degrees.
    Also this worked in the negative direction aswell.

    Anyway... getting to the point... How do i make an object always point towards the mouse with 360 directions? (e.g. not using the 32 directions)

    Thanks for your help in advance.

  2. #2
    Forum Moderator Fusion 2.5 DeveloperAndroid Export ModuleSWF Export Module

    Join Date
    Jun 2006
    Location
    Merseyside, UK
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Rotating Objects Towards the Mouse

    Try build #243 the Clickteam Movement Controller extension includes expressions to retrieve the angle between two points, and to convert between degrees and MMF 32 dir depending on what you need.

  3. #3
    No Products Registered

    Join Date
    Aug 2006
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Rotating Objects Towards the Mouse

    Ok, thanks for he quick reply.

    At the moment I'm using the demo, which the new build is not compatible with.

    But I guess I'll buy the full version then, as I've only got TGf 1 at the moment.

    Thanks again.

  4. #4
    No Products Registered

    Join Date
    Jun 2006
    Location
    Texas
    Posts
    1,002
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Rotating Objects Towards the Mouse

    make sure that ATan returns degrees and not radians. Also if you wanted to make sure that there was no negative values take your degree value, add 360, and then modulate by 360 so:

    (DegAngle+360) mod 360 would be your angle.

  5. #5
    Clicker Fusion 2.5

    Join Date
    Sep 2006
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Rotating Objects Towards the Mouse

    Now I'm definitely curious. I have an idea that's similar to how the missiles work in Starcraft (if anyone's ever played it or edited it). Would someone know how to make projectile objects turn towards a target? Not just setting it to face the object but say if you want a missile to heat seek something, but when the missile is launched from one spot, it isn't shooting out straight but is instead shooting out at an angle and then curves towards the target. I've got something similar to work, but it looks pretty ugly and not nearly as fluid.

  6. #6
    No Products Registered

    Join Date
    Jun 2006
    Location
    Texas
    Posts
    1,002
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Rotating Objects Towards the Mouse

    Yeah but it would take a bit of math or a few extensions.

    px and py is the position of our object. ang is the angle is the current angle that our missle is moving at. speed is the speed at which the missle is moving. target x and target y is the position that you want to hit.

    that said you can get the angle you need to rotate to using:

    dx=cos(ang)
    dy=sin(ang)

    tx=targetx-px
    ty=targety-py

    distance=sqrt(tx*tx+ty*ty)
    tx/=distance
    ty/=distance

    s=(dy*tx-dx*ty)%360
    dot=dx*tx+dy*ty

    ang-=acos(dot)*s


    You can control the speed of rotation by limiting the amount you subtract from the angle.

    This should be done every so often to correct the missles trajectory (To make it track).

    To make an object move at this angle we use:

    vx=cos(ang)*speed
    vy=sin(ang)*speed

    px+=vx
    py+=vy

    that should work .

  7. #7
    Clicker Fusion 2.5

    Join Date
    Sep 2006
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Rotating Objects Towards the Mouse

    If you could email me maybe a small example of that in action in maybe a .gam file, that'd be nice! I haven't done any Trigonometry in maybe five years... Don't really know how to do any of that stuff anymore. Hehe.

  8. #8
    No Products Registered

    Join Date
    Jun 2006
    Location
    Texas
    Posts
    1,002
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Rotating Objects Towards the Mouse

    I only have MMF 1.5 and MMF 2. I don't have TGF 2, therefore I can't make an example .

  9. #9
    Clicker Fusion 2.5

    Join Date
    Sep 2006
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Rotating Objects Towards the Mouse

    There's gotta be a way I can open those files. =X What's the extensions? I think they're all compatible with each other, kinda like the Microsoft Office package and much of the Adobe software.

    *.mfa,*.cca,*.gam,amd *.lib

  10. #10
    Forum Moderator Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    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)

    Join Date
    Jun 2006
    Location
    England
    Posts
    3,546
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)

    Re: Rotating Objects Towards the Mouse

    The levels of file format compatibility is generally speaking thus: You can open files on an equal or lower level but only save to the current level. An excpetion to loading is when there is a difference in functionality.

    Level 6: Multimedia Fusion 2; The Games Factory 2
    Level 5: Multimedia Fusion 1.5
    Level 4: Multimedia Fusion 1.2 (?)
    Level 3: Multimedia Fusion 1.0
    Level 2: The Games Factory; Click & Create; Multimedia Fusion Express
    Level 1: Klik & Play (inc. KNP 4 Schools)

    ...Something like that.
    .:::.Joshtek.:::.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Rotating objects?
    By Zambaku in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 9th March 2009, 01:34 AM
  2. Rotating objects around a point
    By Raylax in forum File Archive
    Replies: 14
    Last Post: 28th December 2008, 11:17 PM
  3. Rotating objects around a point
    By Raylax in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 24th December 2008, 04:56 PM
  4. Rotating objects: diagonals look bad
    By Leander in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 24th July 2008, 10:16 PM
  5. Rotating Objects Question
    By Jellyhead365 in forum The Games Factory 2 - Technical Support
    Replies: 1
    Last Post: 28th October 2006, 01:01 AM

Posting Permissions

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