Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

connecting cables

Discussion in 'Physics' started by pachermann, Aug 16, 2019.

  1. pachermann

    pachermann

    Joined:
    Dec 18, 2013
    Posts:
    62
    Hi

    I want to connect cable ends, when do so i can't manage to freeze the positions of both cable and target.
    I used the .FreezeALL constrains and it activated it but that does not much.

    any Inputs?

    Video: http://www.frontend-nerds.ch/download/snap_cable.mp4

    this is my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class connectors : MonoBehaviour
    6. {
    7.  
    8.     #region Class members
    9.     [SerializeField] private bool snapped;
    10.     public RigidbodyConstraints constraints { get; private set; }
    11.     #endregion
    12.  
    13.     private void OnTriggerEnter(Collider other)
    14.     {
    15.         Debug.Log("hit");
    16.  
    17.  
    18.         if (other.tag.Equals("Cable_end") || other.tag.Equals("Cable_start"))
    19.         {
    20.             snapped = true;
    21.  
    22.             var cable = GetComponent<Joint>();
    23.             cable.connectedBody = other.GetComponent<Rigidbody>();
    24.  
    25.             cable.connectedBody.constraints = RigidbodyConstraints.FreezeAll;
    26.           // cable.connectedBody.drag = 0;
    27.  
    28.         }
    29.  
    30.         if (snapped)
    31.         {
    32.             Debug.Log("Kabel snapped: " + other.name);
    33.         }
    34.     }
    35.    
    36.  
    37. }
    38.  
     
    Last edited: Aug 16, 2019