How do you stick one object to another at position and direction?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Almost like a drag and drop, but not with a mouse, I'm trying to make it so that when one Active Object overlaps a second Active Object, the second Active Object sticks to the first at the coordinates they overlap, and also stay at that relative positioning depending on which way the first Active Object rotates. A bit like a manual "Set Position" action but with varied X and Y values.

    And... I haven't been able to figure it out. Have been messing with Sin and Cosine and distances a bit but it's still not working right.

    Please login to see this attachment.

    Edited 2 times, last by Kid_Roleplay (June 28, 2015 at 5:39 PM).

  • On collision, trigger a flag and store the arc tangent of the distance between the two objects as an alterable value: ATan2(object A's Xpos - object B's Xpos, object B's Ypos - object A's Ypos). This will create the angle you can use in your Sine and Cosine calls, so set Object B's X position to Object A's X position + Sin (Arc Value), and Set Object B's Y position to Object Y's Y position - Cos (Arc Value).

  • That looks neat. I can tell that it's similar to what I'm trying to figure out though. Basically in my first example, I want it so that when you press "Z," the object that changes color doesn't move and becomes fixed to that spot on the larger object no matter where said larger object is placed in the future or which way it rotates.

  • Hello Kid_Roleplay,

    I still can't clearly figure out what you're needing,
    you would like to "fix" the green diamond active into the "blue square" object at any given position,
    and keep it so that if you rotate the blue object, green diamond keeps remaining in its correct fixed position?

    a selection of my Fusion examples can be found Please login to see this link.

  • Well, the concept is the same and should be adaptable. Are you trying to account for like being hit by an arrow (projectile), being held on to by an enemy, or picking up a weapon?

    I think it's fairly easy until you want to move between frames. You would need to capture the attach points and save them for future use. Actually, you'll have to capture the points of contact anyway so you can always have the object affixed to the player. I *think* an issue you might be grappling with is how to attach single instances of like objects to the player. When the object collides or overlaps the player:

    1) capture the fixed ID of the object that is colliding. I don't think this step is absolutely necessary but it might come in handy so you can specifically deal with the individual objects when needed.
    2) capture the coordinates of impact relative to the player, store with the object
    3) turn on a flag on the object
    2) in a separate event, based on the flag, change the animation or color of the object to reflect what you want it to look like. This will take care of every like object in the future.
    3) Now the fun part, I think you need a for each loop on each object...someone can correct me. For each object that has a flag active, 'attach' to the player at the stored points at the current angle. The attach code is what keeps keeps it in place and referenced as the player angle changes.

    I would start there. I don't know if I'm good enough to program this out myself in short order (I have my own issues to deal with) but I think the above is what you want. Start simple, like just see if you can get the object to collide and change its animation. Than try to affix it to the player.

  • Hello Kid_Roleplay,

    I still can't clearly figure out what you're needing,
    you would like to "fix" the green diamond active into the "blue square" object at any given position,
    and keep it so that if you rotate the blue object, green diamond keeps remaining in its correct fixed position?

    Yup. That's correct. :) And no matter which direction the "blue square" object is already facing. My ... attempt... to try to get that to work is in the first attachment.

  • To Jarred: I'm looking for the Math or MMF2 equivalent of doing a "Set position of Object B to (X, Y) from Object A's location and direction," but through expressions such to allow the use of variables.

    As if you were to cut out a rectangular piece of duct tape and held it flat, then pressed its sticky side down onto a paperclip. The paperclip will be stuck to that spot no matter which way the duct tape was originally facing, and will move and rotate with the duct tape until it is pulled off again.

    Fixed values and the like I'm not worried over at the moment and know how to do. It's just this no-good, evil math stuff that's making me pout.

  • Oh that's pretty simple!
    OAngle gets the angle of an object from a specified X,Y point
    ODistance gets the distance of an object from a specified X,Y point
    (you find both in the expression editor under "position" submenu of the object)

    So, since we want to move the object in a fixed circumference around a central point (bigblue hotspot)
    I just saved the "distance" as the radius of the circle,
    and rotated the object position at moving angle of the radius
    (then rotate the whole object to same angle as bigblue to keep it angled in the same way)

    glad it worked ok! XD

    a selection of my Fusion examples can be found Please login to see this link.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!