Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to pull, drag, and throw objects

Discussion in 'Physics' started by fighter453, Dec 23, 2015.

  1. fighter453

    fighter453

    Joined:
    Dec 23, 2015
    Posts:
    6
    I am creating a game similar to Operation in which the player needs to pull a small object out of a large object as carefully as possible. Once the object is pulled out they need to throw the object into the bin to remove it from the play area. I have found various tutorials online on how to pickup and drop objects, but the pickup is nearly instantaneous and I would like some advice on how I can pull the object based on the mouse/touch screen. Also, being able to throw the object based on how fast the user flicks the mouse/screen.

    Any advice would be greatly appreciated.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,560
    For 2D physics you can use the TargetJoint2D. When you mouse-down, you can add/enable this component and set both the target and anchor properties to the mouse-position. When you drag the mouse, update the target property to the mouse-position. When you mouse-up, disable/delete this component.

    You can configure the max-force, frequency and damping-ratio to give you the effect you want, typically how hard/soft the drag-force is (acts like a spring).

    As an example, you can see objects being picked-up here. NOTE: that in the video, the spring is very soft.

    If it's 3D physics then I'm not sure; maybe a SpringJoint would be best.
     
  3. fighter453

    fighter453

    Joined:
    Dec 23, 2015
    Posts:
    6
    MelvMay,

    While in the process of looking into your way to implement this I found something easier here. Thanks for your help as it lead me in the right direction