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

Get help using Construct 2

Post » Thu Sep 01, 2016 4:02 pm

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.

Image

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?
Last edited by matriax on Thu Sep 01, 2016 6:10 pm, edited 1 time in total.
B
25
S
10
G
3
Posts: 580
Reputation: 4,562

Post » Thu Sep 01, 2016 6:10 pm

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
Mistakes were made.
B
53
S
27
G
114
Posts: 1,698
Reputation: 64,444

Post » Thu Sep 01, 2016 6:59 pm

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

Image

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?
B
25
S
10
G
3
Posts: 580
Reputation: 4,562

Post » Thu Sep 01, 2016 8:17 pm

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.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,698
Reputation: 64,444

Post » Thu Sep 01, 2016 9:17 pm

@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.
B
25
S
10
G
3
Posts: 580
Reputation: 4,562

Post » Thu Sep 01, 2016 9:38 pm

[deleted]
EDIT: Never mind what I said previously! Different approach has been found as per your requirement.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,698
Reputation: 64,444

Post » Fri Sep 02, 2016 1:20 am

New approach for perpendicular tracking of mouse as requested. Simpler too.

https://www.dropbox.com/s/y373s7br405fk ... .capx?dl=0
Mistakes were made.
B
53
S
27
G
114
Posts: 1,698
Reputation: 64,444

Post » Fri Sep 02, 2016 7:15 am

@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 :P

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! ;)
B
25
S
10
G
3
Posts: 580
Reputation: 4,562


Return to How do I....?

Who is online

Users browsing this forum: wertt22, Yahoo [Bot] and 23 guests