User Tag List

Results 1 to 7 of 7

Thread: How to move an object from XY space to another XY space

  1. #1
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,156
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)

    Question How to move an object from XY space to another XY space

    I have made a thread in the past about making a bird movement and was using the base of an example that used the easing object. This caused problems though with parallaxing and I now want to try to just move the bird with regular values. However I just realized that I have never actually had to do such a movement in my games before. That is, from an XY position somewhere in the frame to another XY position. I want to do it without inbuilt movements. The most simple way would of course be to just have a move value say 1 and then if the X or Y position is greated than the objects just move that 1 pixel to the right and down. But it would look sloppy when it reach say the X position and then just moves straight down. I want to make it so the object moves in a "line" from one XY position to another position. How do one best do this?

  2. #2
    Clicker Fusion 2.5
    Warmachine's Avatar
    Join Date
    Nov 2009
    Location
    Charleston, WV
    Posts
    653
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Im not sure how smooth it would look, i would suspect less sinewave and more graph-spikes-lack of better term lol. But you may be able to get away with something like:

    (Compare 2 general values) - insert starting X is lower than ending x = mid x point (for the drop or rise in the movement). Then just add to the x position. Same thing with the Y in a separate event. Then make another line from the mid x/y point to the final x/y point? Like i said, not sure if it would work but worth a shot without extensions.

  3. #3
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    640
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    You need to take into account the angle between the target and the moving object, then modify the position by this angle using cosine. Here's an example. It supports speed being a float (speed is divided by 100, so 500 = 5 , 550 = 5.5 etc), makes sure the object doesn't overshoot the target, and doesn't rely on a time value. Move the red target using arrow keys. There is a flag that will be set to TRUE when the object has reached its target if needed.
    Attached files Attached files

  4. #4
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,156
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by casleziro View Post
    You need to take into account the angle between the target and the moving object, then modify the position by this angle using cosine. Here's an example. It supports speed being a float (speed is divided by 100, so 500 = 5 , 550 = 5.5 etc), makes sure the object doesn't overshoot the target, and doesn't rely on a time value. Move the red target using arrow keys. There is a flag that will be set to TRUE when the object has reached its target if needed.
    Thank you! This should be perfect to work from!

  5. #5
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,156
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by casleziro View Post
    You need to take into account the angle between the target and the moving object, then modify the position by this angle using cosine. Here's an example. It supports speed being a float (speed is divided by 100, so 500 = 5 , 550 = 5.5 etc), makes sure the object doesn't overshoot the target, and doesn't rely on a time value. Move the red target using arrow keys. There is a flag that will be set to TRUE when the object has reached its target if needed.
    Just one question about the example, in the last two events you have two events and a comment "set flag on when object is at target, checking if distance is lower than a fixed distance of 0.001 to avoid rounding errors"

    However I see that these two events toggles the "at target" flag on or off, but I don't see any other events that use or reference this flag and its state so what are the reason for these events?

  6. #6
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    640
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    @Outcast that flag is just there in case you needed to know the object has finished its movement. Those events aren't used in the example and can be deleted if you don't want them. I figured since you were using this for your birds movement (?) that you might want to only start a timer when "at target" is on.

  7. #7
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,300
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I would usually do something like this:

    + new target assigned...
    -> Sprite: set targetDist to sqr(((targetX - posX("Sprite")) pow 2) + ((targetY - posY("Sprite")) pow 2))
    // get a unit vector (vector with length of 1) to the target
    -> Sprite: set moveX to (targetX - posX("Sprite")) / targetDist("Sprite")
    -> Sprite: set moveY to (targetY - posY("Sprite")) / targetDist("Sprite")

    + if targetDist > 0
    // move towards the target without overshooting
    -> Sprite: set posX to posX("Sprite") + (moveX("Sprite") * min( velocity("Sprite"), targetDist("Sprite")))
    -> Sprite: set posY to posY("Sprite") + (moveY("Sprite") * min( velocity("Sprite"), targetDist("Sprite")))
    -> Sprite: set targetDist to targetDist("Sprite") - velocity("Sprite")


    The only complex (ie. slow) maths being done is to calculate the distance to the target (there's no trig anywhere), and that only happens once, when a new target is assigned. The maths used to move the object each frame is simple and fast.

Similar Threads

  1. Object sorting in a faux-3D Space?
    By bhlaab in forum Fusion 2.5
    Replies: 1
    Last Post: 12th November 2017, 06:01 AM
  2. Galactic Space Agency (A 2D game inspired by Kerbal Space Program) [PC]
    By MYCRAFTisbest in forum WIP & Released Games & Apps
    Replies: 4
    Last Post: 9th May 2016, 12:39 AM
  3. Does an Object's 'Behavior' take up a lot of space?
    By Daniel_M in forum Fusion 2.5
    Replies: 2
    Last Post: 15th January 2016, 02:47 AM
  4. Pipe Object FYI - Parameter needs space.
    By droberson in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 25th August 2007, 04:54 PM
  5. [request] Window Space Object
    By MelliGeorgiou in forum Extension Development
    Replies: 9
    Last Post: 5th July 2007, 08:43 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
  •