Search Unity

[2D] Is there an easy way to drag physicalized objects?

Discussion in 'Physics' started by LilGames, Jun 7, 2017.

  1. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
    Hi. OK, since Unity Physics2D is using Box2D, I can't help but wonder if it supports the "built in" dragging option that I saw Box2D had in its Flash form? What I mean is this: http://www.sideroller.com/wck/

    That's a component based implementation of Box2D for Flash. If you look at the image below that Flash demo, the component panel shows an option called "allowDragging". This enables literal dragging via click an drag of the mouse pointer (or a touch on mobile).

    If you play with the demo on that page, many objects are click-draggable. Most fun to play with is the buoyancy demo page. Click and drag the raggdolls.


    So what I'm getting at with this thread is, how do I implement this dragging feature EASILY and correctly in Unity? Is it built into Box2D or was that an addition specific to WCK?

    I tried adding a SpringJoint2D and some code I found in a Unity Answers discussion (here: http://answers.unity3d.com/questions/1010515/2d-click-anywhere-on-physics-object-and-drag.html ), but I don't think it's quite the same (note how in the Flash WCK demos, the spot you click becomes the pivot point!)

    I welcome any insight into this. Thanks in advance.