Joint + drag max distance

Get help using Construct 2

Post » Sat Dec 28, 2013 2:34 am

Hello there,
I have been lurking in this forum for few months now and started to build my app with C2. There is one thing among many I can't figure out yet. The task is simple but I just don't know how to search for it or how it is named.

Let's say I want to drag with touch event some body part that is pinned or jointed to the body. Now I would like to create max distance it could be dragged so it doesn't look like you are dragging it out from the body. Also it should bounce back nicely.

Can anyone link to some example or explain how is max distance for dragging done?

Thanks in advance!
B
11
S
1
Posts: 15
Reputation: 521

Post » Sat Dec 28, 2013 2:39 am

B
11
S
1
Posts: 15
Reputation: 521

Post » Sat Dec 28, 2013 7:41 am

I'm not quite sure what effect you are trying to create, but a simple solution for limiting the drag would be comparing the distance I guess.

Would this work?

sprite1 is dragging
system compare two values: distance(sprite1.x, sprite1.y, sprite2.x, sprite2.y) > 100
-sprite1 stop dragging
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 28, 2013 9:21 am

Thanks LittleStain! That's almost what I need.
Now there should be some bounciness and the dragged object should move back to its original position as image point. The entire drag action should feel very elastic :)

I'm not a programmer but trying to dig myself deeper into that.

I made example file:
https://www.dropbox.com/s/64zkshx5dd5zh7l/drag-test.capx

Should I use now just physics or I need little extra behavior like Gravity (to add also new gravity point)?
B
11
S
1
Posts: 15
Reputation: 521

Post » Sat Dec 28, 2013 10:40 am

Maybe you could do something like this:
add two instance variables startx and starty.

on drag start
- sprite set startx to sprite.x
- sprite set starty to sprite.y

sprite on is not dragging
- sprite set x to : lerp(sprite.x,sprite.startx,0.5)
- sprite set y to : lerp(sprite.y,sprite.starty,0.5)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 28, 2013 11:55 am

Ohh, thanks again! I'll try your suggestion out for the next.
I tried this: .CAPX with the "Sine". Only thing missing now is the deceleration.
B
11
S
1
Posts: 15
Reputation: 521


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests