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. Dismiss Notice

DistanceJoint2D Object Disapearing.

Discussion in '2D' started by DonPerry, Apr 29, 2014.

  1. DonPerry

    DonPerry

    Joined:
    Oct 4, 2012
    Posts:
    16
    I'm trying to have a character pick up an object.

    The character object has an empty child game object with a box collider that acts as his 'hands'

    Well, it doesn't quite disappear... It seems like everything's working fine except the sprite isn't rendering after picked up.

    Also after dropping the object it is still stuck in the aether.

    Here's my code
    Code (csharp):
    1.  
    2.  
    3.     private bool isHolding = false;
    4.     private GameObject currentObject;
    5.     private DistanceJoint2D currentHinge;
    6.     void Start () {
    7.  
    8.     }
    9.  
    10.     void Update () {
    11.         if (currentObject != null  !isHolding) {
    12.             Debug.Log (currentObject.ToString());
    13.             currentHinge = currentObject.GetComponent<DistanceJoint2D>();
    14.             currentHinge.transform.parent = gameObject.transform.parent;
    15.             currentHinge.enabled = true;
    16.             isHolding = true;
    17.         }
    18.  
    19.     }
    20.  
    21.     void OnTriggerEnter2D(Collider2D item){
    22.         DistanceJoint2D hinge = item.GetComponent<DistanceJoint2D>();
    23.         if (hinge != null){
    24.             if(Input.GetKey(grabButton)){
    25.                 currentObject = item.gameObject;
    26.             }
    27.         }
    28.     }
    29.  
     
    Last edited: Apr 29, 2014
  2. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
    Uh, shouldn't you be setting connectedBody instead of parent?
     
  3. DonPerry

    DonPerry

    Joined:
    Oct 4, 2012
    Posts:
    16
    Oh duh! Brainfart. Thanks man!