Joint + drag max distance

0 favourites
  • 6 posts
From the Asset Store
AppLovin MAX Ads
$8 USD
20% off
Support AdType ( AppOpenAd, Banner Ad, Interstitial Ad Rewarded Ad, MREC Ad) support c3 build service
  • 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.

    <img src="https://www.dropbox.com/s/jtdspb2hasyz12s/drag.png" border="0" />

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

    Thanks in advance!

  • <img src="http://www.digitar.ee/games/drag.png" border="0" />

  • 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

  • Thanks LittleStain! That's almost what I need. <img src="smileys/smiley32.gif" border="0" align="middle" />

    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:

    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)?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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)
  • 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.

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