How do I drag/lock an object only at given angle/axis?

0 favourites
  • 8 posts
From the Asset Store
Use inertion of your movements to throw, rotate your objects and etc. Objects can interact with others while dragging.g
  • Seems is impossible do it for the pointer so, how can i do it for a sprite?

    Some perfect will be limit the movement of an object to a given angle.

    With drag and drop with Axis in Both i can drag everywhere. And with horizontal or vertical i can move the object in X or Y axis.

    But how i can set a custom angle to drag the object?

    If not with drag&drop what plugin/behaviour i have to use?

  • To do so, you'll need to save the originalposition of the object in variable when you start dragging, then set object position to x, y where x is mouse or touch.x, and y is tan(angle)*(mouse.x-originalx)+originaly

  • oosyrag Seems this is the way but it's a bit buggy.

    A better image to explain better how/where to move. Or maybe your expresion is correct and i'm doing something wrong.

    i 'm going to play around the last expresion again to see if i can get it.

    So there is no plugin/behavior to lock some object position to an angle?

  • Sorry messed up a bit on the math. Here is a partial example:

    https://www.dropbox.com/s/6j58ma2hlg7z2 ... .capx?dl=0

    Some issues that need to be addressed:

    Sprite jumps to cursor upon first click - Can be adjusted for by storing the difference between Mouse.X and Sprite.X in a variable

    Doesn't work with 90 or 270 degree angles

    Only works on X motion - Both of these can be fixed by making a second version that works on the y axis, and utilizing proper conditions to choose which one to use based on mouse movement.

  • oosyrag Thanks!, now works smooth, but is there anyway to get the math to work like the last image i posted?

    In the image while the pointer is in perpendicular to the object axis not move down/up stay in the same position.

    I tried to change the expresion for curiosity in your .capx , but damn al turns into a mess so fast XDD.

  • [deleted]

    EDIT: Never mind what I said previously! Different approach has been found as per your requirement.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • New approach for perpendicular tracking of mouse as requested. Simpler too.

    https://www.dropbox.com/s/y373s7br405fk ... .capx?dl=0

  • oosyrag THANKS!

    Really? All this for you is simpler? damn i want your brain! XD

    cos(anglediff(SetAngle,angle(Sprite.x0,Sprite.y0,Mouse.X,Mouse.Y)))*distance(mouse.X,mouse.Y,Sprite.x0,Sprite.y0)

    XDDD Maybe if you like math or have some skills, but for us, the mortals, is other thing

    Now is apply all this to my program design for every sprite scaler but i hope get working today.

    Again, thanks for your help and time!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)