public override void OnSelection(RUISWandSelector selector)
	{
		this.selector = selector;
		// Transform information
		positionAtSelection = selector.selectionRayEnd;
		rotationAtSelection = transform.rotation;
		// Selector information
		selectorPositionAtSelection = selector.transform.position;
		selectorRotationAtSelection = selector.transform.rotation;
		distanceFromSelectionRayOrigin = (selector.selectionRayEnd - selector.selectionRay.origin).magnitude; // Dont remove this, needed in the inherited class
		
		
		this.originalJointDriveX = this.configurableJoint.angularXDrive;
		this.originalJointDriveYZ = this.configurableJoint.angularYZDrive;
		
		JointDrive jd = new JointDrive();
		jd.mode = JointDriveMode.Position;
		jd.positionSpring = springForce;
		jd.maximumForce = 999;
		
		this.configurableJoint.angularXDrive = jd;
		this.configurableJoint.angularYZDrive = jd;

		if (selectionMaterial != null)
			AddMaterialToEverything(selectionMaterial);
	}
Example #2
0
    public static void attachChainHook(this ConfigurableJoint cj, GameObject attachedGo)
    {
        JointDrive jd = new JointDrive();
        jd.mode = JointDriveMode.Position;
        jd.positionDamper = 0.4f;
        cj.slerpDrive = jd;

        cj.xMotion = ConfigurableJointMotion.Locked;
        cj.yMotion = ConfigurableJointMotion.Locked;
        cj.zMotion = ConfigurableJointMotion.Locked;

        cj.angularXMotion = ConfigurableJointMotion.Limited;
        cj.angularYMotion = ConfigurableJointMotion.Limited;
        cj.angularZMotion = ConfigurableJointMotion.Limited;	//set limits again since this object rotation has been altered
        SoftJointLimit limit = new SoftJointLimit();
        limit.limit = -80f;
        cj.lowAngularXLimit = limit;

        limit.limit = 80f;
        cj.highAngularXLimit = limit;

        limit.limit = 3f;
        cj.angularYLimit = limit;

        limit.limit = 80f;
        cj.angularZLimit = limit;

        if (attachedGo.rigidbody != null)
            cj.connectedBody = attachedGo.rigidbody;
    }
    public void In(
#if (UNITY_3_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2)
      [FriendlyName("Mode", "The JointDriveMode.")]
      JointDriveMode mode,
#endif
      [FriendlyName("Position Spring", "The JointDrive PositionSpring.")]
      float positionSpring,

      [FriendlyName("Position Damper", "The PositionDamper of the JointDrive.")]
      float positionDamper,

      [FriendlyName("Maximum Force", "The MaximumForce of the JointDrive.")]
      float maximumForce,

      [FriendlyName("Joint Drive", "The newly created JointDrive.")]
      out JointDrive jointDrive
      )
    {
        JointDrive j = new JointDrive();
        #if (UNITY_3_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2)
          j.mode = mode;
        #endif
          j.positionSpring = positionSpring;
          j.positionDamper = positionDamper;
          j.maximumForce = maximumForce;

          jointDrive = j;
    }
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.JointDrive o;
         o = new UnityEngine.JointDrive();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
   public void In(
      [FriendlyName("Mode", "The JointDriveMode.")]
      JointDriveMode mode,
      
      [FriendlyName("Position Spring", "The JointDrive PositionSpring.")]
      float positionSpring,
      
      [FriendlyName("Position Damper", "The PositionDamper of the JointDrive.")]
      float positionDamper,

      [FriendlyName("Maximum Force", "The MaximumForce of the JointDrive.")]
      float maximumForce,
      
      [FriendlyName("Joint Drive", "The newly created JointDrive.")]
      out JointDrive jointDrive
      )
   {
      JointDrive j = new JointDrive( );
      
      j.mode = mode;
      j.positionSpring = positionSpring;
      j.positionDamper = positionDamper;
      j.maximumForce   = maximumForce;

      jointDrive = j;
   }
Example #6
0
	protected void holdObject(GameObject obj, Vector3 holdPoint) {
		grabbed = obj;

		Physics.IgnoreCollision(GetComponent<Collider>(), grabbed.GetComponent<Collider>(), true);

		// create and configure the joint
		driver = new JointDrive();
		driver.mode = JointDriveMode.Position;
		driver.positionDamper = strength /5;
		driver.positionSpring = strength *3f;
		driver.maximumForce = strength *3;

		holdJoint = grabbed.AddComponent<ConfigurableJoint>();
		holdJoint.autoConfigureConnectedAnchor = false;
		holdJoint.rotationDriveMode = RotationDriveMode.Slerp;
		//holdJoint.breakForce = 15f;

		holdJoint.connectedBody = this.gameObject.transform.GetChild(0).GetComponent<Rigidbody>();
		holdJoint.connectedAnchor = normalHoldPosition;
		if ((grabbed.GetComponent<Rigidbody>().worldCenterOfMass -holdPoint).sqrMagnitude > holdDistance)
			holdJoint.anchor = grabbed.transform.InverseTransformPoint(holdPoint);
		else
			holdJoint.anchor = grabbed.GetComponent<Rigidbody>().centerOfMass;
		holdJoint.projectionDistance = 0;
		holdJoint.projectionAngle = 0;
		holdJoint.xDrive = holdJoint.yDrive = holdJoint.zDrive = holdJoint.slerpDrive = driver;
		holdJoint.targetPosition = Vector3.zero;
	}
    static public int set_positionDamper(IntPtr l)
    {
        UnityEngine.JointDrive o = (UnityEngine.JointDrive)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.positionDamper = v;
        setBack(l, o);
        return(0);
    }
    static public int set_maximumForce(IntPtr l)
    {
        UnityEngine.JointDrive o = (UnityEngine.JointDrive)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.maximumForce = v;
        setBack(l, o);
        return(0);
    }
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.JointDrive o;
			o=new UnityEngine.JointDrive();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
Example #10
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.JointDrive o;
         o = new UnityEngine.JointDrive();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.JointDrive o;
         o = new UnityEngine.JointDrive();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.JointDrive o;
         o=new UnityEngine.JointDrive();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
Example #13
0
 static void CharacterJoint_rotationDrive(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.CharacterJoint _this = (UnityEngine.CharacterJoint)vc.csObj;
         var result = _this.rotationDrive;
         JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.JointDrive     arg0  = (UnityEngine.JointDrive)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
         UnityEngine.CharacterJoint _this = (UnityEngine.CharacterJoint)vc.csObj;
         _this.rotationDrive = arg0;
     }
 }
 static void ConfigurableJoint_slerpDrive(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.ConfigurableJoint _this = (UnityEngine.ConfigurableJoint)vc.csObj;
         var result = _this.slerpDrive;
         JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.JointDrive        arg0  = (UnityEngine.JointDrive)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
         UnityEngine.ConfigurableJoint _this = (UnityEngine.ConfigurableJoint)vc.csObj;
         _this.slerpDrive = arg0;
     }
 }
Example #15
0
    public static void DisableConfigurableJoint(this ConfigurableJoint cj)
    {
        cj.connectedBody = null;
        cj.xMotion = ConfigurableJointMotion.Free;
        cj.yMotion = ConfigurableJointMotion.Free;
        cj.zMotion = ConfigurableJointMotion.Free;

        cj.angularXMotion = ConfigurableJointMotion.Free;
        cj.angularYMotion = ConfigurableJointMotion.Free;
        cj.angularZMotion = ConfigurableJointMotion.Free;

        JointDrive jd = new JointDrive();
        jd.mode = JointDriveMode.None;

        cj.slerpDrive = jd;
    }
Example #16
0
// fields

// properties
    static void JointDrive_mode(JSVCall vc)
    {
        if (vc.bGet)
        {
            UnityEngine.JointDrive _this = (UnityEngine.JointDrive)vc.csObj;
            var result = _this.mode;
            JSApi.setEnum((int)JSApi.SetType.Rval, (int)result);
        }
        else
        {
            UnityEngine.JointDriveMode arg0  = (UnityEngine.JointDriveMode)JSApi.getEnum((int)JSApi.GetType.Arg);
            UnityEngine.JointDrive     _this = (UnityEngine.JointDrive)vc.csObj;
            _this.mode = arg0;
            JSMgr.changeJSObj(vc.jsObjID, _this);
        }
    }
Example #17
0
 static void JointDrive_maximumForce(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.JointDrive _this = (UnityEngine.JointDrive)vc.csObj;
         var result = _this.maximumForce;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single          arg0  = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.JointDrive _this = (UnityEngine.JointDrive)vc.csObj;
         _this.maximumForce = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
        /// <summary>
        /// Read the data using the reader.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public override object Read(ISaveGameReader reader)
        {
            UnityEngine.JointDrive jointDrive = new UnityEngine.JointDrive();
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "positionSpring":
                    jointDrive.positionSpring = reader.ReadProperty <System.Single> ();
                    break;

                case "positionDamper":
                    jointDrive.positionDamper = reader.ReadProperty <System.Single> ();
                    break;

                case "maximumForce":
                    jointDrive.maximumForce = reader.ReadProperty <System.Single> ();
                    break;
                }
            }
            return(jointDrive);
        }
Example #19
0
 private extern void INTERNAL_get_slerpDrive(out JointDrive value);
    void NewJoint( int i )
    {
        GameObject tJC;
        ConfigurableJoint tCJ;
        SoftJointLimit sjl;
        JointDrive jd;
        //CapsuleCollider cc;

        tJC = new GameObject("Connection_"+i.ToString());
        tJC.transform.position = ropeEnd.transform.position + (jointHeading * linkLength * i);
        tJC.transform.LookAt(transform.position);

        Debug.Log( i );
        if( jointParent == null ) {
            tJC.transform.parent = GameObject.Find( "Rope" ).transform;
        }
        else {
            tJC.transform.parent = jointParent.transform;
        }
        tJC.AddComponent<Rigidbody>();
        //tJC.rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
        tJC.rigidbody.angularDrag = 0;

        switch(constraintPlane)
        {
            case ConstraintPlane.X_Y:
                tJC.rigidbody.constraints = RigidbodyConstraints.FreezePositionZ;
                break;
            case ConstraintPlane.Y_Z:
                tJC.rigidbody.constraints = RigidbodyConstraints.FreezePositionX;
                break;
            case ConstraintPlane.Z_X:
                tJC.rigidbody.constraints = RigidbodyConstraints.FreezePositionY;
                break;
            default:
                break;
        }

        /* Uncomment this to add capsule colliders to the links.
        if(i<linkCount)
        {
            cc = tJC.AddComponent<CapsuleCollider>();
            cc.center = new Vector3(0,0,jointGap/2);
            cc.height = jointGap * 1.33f;
            cc.direction = 2;
            cc.radius = ropeRadius;
        }*/

        tCJ = tJC.AddComponent<ConfigurableJoint>();
        tCJ.configuredInWorldSpace = true;
        try{tCJ.connectedBody = jointConnections[i-1].rigidbody; }catch{ tCJ.connectedBody = ropeEnd.rigidbody; }

        //tCJ.swingAxis = new Vector3(1,1,1);
        tCJ.xMotion = ConfigurableJointMotion.Locked;
        tCJ.yMotion = ConfigurableJointMotion.Locked;
        tCJ.zMotion = ConfigurableJointMotion.Locked;

        tCJ.angularXMotion = ConfigurableJointMotion.Locked;
        tCJ.angularYMotion = ConfigurableJointMotion.Locked;
        tCJ.angularZMotion = ConfigurableJointMotion.Locked;
        /*
        tCJ.angularXMotion = ConfigurableJointMotion.Limited;
        tCJ.highAngularXLimit = new SoftJointLimit(){ limit = 360.0f };
        tCJ.lowAngularXLimit = new SoftJointLimit(){ limit = 0.0f };
        tCJ.angularYMotion = ConfigurableJointMotion.Limited;
        tCJ.angularYLimit = new SoftJointLimit(){ limit = 360.0f };
        tCJ.angularZMotion = ConfigurableJointMotion.Limited;
        tCJ.angularZLimit = new SoftJointLimit(){ limit = 360 }; //MinMaxTwist };
        */

        jd = new JointDrive() { mode = JointDriveMode.Position };
        tCJ.xDrive = jd;
        tCJ.yDrive = jd;
        tCJ.zDrive = jd;

        if(i == linkCount)
        {
            // first, update the old end
            /*
            if( i > 1 ) {
                ConfigurableJoint oldcj = (ConfigurableJoint) jointConnections[i-1].GetComponent( "ConfigurableJoint" );
                oldcj.angularXMotion = ConfigurableJointMotion.Locked;
                oldcj.angularYMotion = ConfigurableJointMotion.Locked;
                oldcj.angularZMotion = ConfigurableJointMotion.Locked;

                oldcj.connectedBody = jointConnections[i-2].rigidbody;
            }
            */

            tCJ = tJC.AddComponent<ConfigurableJoint>();

            tCJ.connectedBody = rigidbody;
            tCJ.xMotion = ConfigurableJointMotion.Locked;
            tCJ.yMotion = ConfigurableJointMotion.Locked;
            tCJ.zMotion = ConfigurableJointMotion.Locked;

            tCJ.angularZMotion = ConfigurableJointMotion.Limited;
            sjl = new SoftJointLimit(){ limit = MinMaxTwist };
            tCJ.angularZLimit = sjl;

            jd = new JointDrive() { mode = JointDriveMode.Position };
            tCJ.xDrive = jd;
            tCJ.yDrive = jd;
            tCJ.zDrive = jd;

            tCJ.projectionMode = JointProjectionMode.PositionOnly;
            tCJ.projectionDistance = 0.1f;
        }

        /*
        tCJ.projectionMode = JointProjectionMode.PositionAndRotation;
        tCJ.projectionDistance = 0.1f;
        tCJ.projectionAngle = .1f;
        tCJ.targetRotation = Quaternion.LookRotation( Vector3.up);
        tCJ.angularXDrive = new JointDrive() { mode = JointDriveMode.Position };
        tCJ.angularYZDrive = new JointDrive() { mode = JointDriveMode.Position };
        */
        jointConnections.Add( tJC );
    }
Example #21
0
	/*
	 * Create a configurable joint on this BodyPart connected to target applying resistance back to the previous pose
	 * NOTE: If maxforce is 0, the ragdoll will crumple like a chump
	 * */
	public ConfigurableJoint ConnectTo(BodyPart target, float resistance, float maxForce)
	{
		// store the current rotation and enter initialRotation to create the joint
		Quaternion q = bone.localRotation;
		bone.localRotation = _initialRotation;
		
		// ensure there is a rigidbody
		AddRigidbody();
		rigidbody.isKinematic = true;
		
		// create the new joint and configure it
		joint = gameObject.AddComponent<ConfigurableJoint>();
		joint.connectedBody = target.AddRigidbody(); // NOTE: this function takes care of validation internally
		joint.axis = jointAxis;
		joint.secondaryAxis = jointSecondaryAxis;
		joint.xMotion = 
		joint.yMotion = 
		joint.zMotion = ConfigurableJointMotion.Locked;
		joint.angularXMotion = 
		joint.angularYMotion = 
		joint.angularZMotion = ConfigurableJointMotion.Limited;
		SoftJointLimit limit = new SoftJointLimit();
		limit.limit = xMin;
		joint.lowAngularXLimit = limit;
		limit.limit = xMax;
		joint.highAngularXLimit = limit;
		limit.limit = yMax;
		joint.angularYLimit = limit;
		limit.limit = zMax;
		joint.angularZLimit = limit;
		joint.rotationDriveMode = RotationDriveMode.Slerp;
		JointDrive drive = new JointDrive();
		drive.mode = JointDriveMode.Position;
		drive.positionSpring = resistance;
		drive.maximumForce = maxForce;
		joint.slerpDrive = drive;
		joint.targetRotation = q*Quaternion.Inverse(initialRotation);
		
		// disable world-space configuration to ensure settings are applied
		joint.configuredInWorldSpace = false;
		
		// return to the current orientation
		bone.localRotation = q;
		rigidbody.isKinematic = false;
		
		return joint;
	}
Example #22
0
 private extern void INTERNAL_get_angularYZDrive(out JointDrive value);
		private extern void INTERNAL_set_slerpDrive(ref JointDrive value);
    void SetupJoint(ConfigurableJoint joint)
    {
        SoftJointLimit jointLimit = new SoftJointLimit();
		jointLimit.spring     = 0.0f;
		jointLimit.damper     = 0.0f;
		jointLimit.bounciness = 0.0f;
		
		JointDrive jointDrive     = new JointDrive();
		jointDrive.mode           = JointDriveMode.Position;
		jointDrive.positionSpring = LinkJointSpringValue;
		jointDrive.positionDamper = LinkJointDamperValue;
		jointDrive.maximumForce   = LinkJointMaxForceValue;

        joint.axis              = Vector3.right;
        joint.secondaryAxis     = Vector3.up;
		joint.breakForce        = LinkJointBreakForce;
		joint.breakTorque       = LinkJointBreakTorque;

		joint.xMotion           = ConfigurableJointMotion.Locked;
		joint.yMotion           = ConfigurableJointMotion.Locked;
		joint.zMotion           = ConfigurableJointMotion.Locked;
		joint.angularXMotion    = Mathf.Approximately(LinkJointAngularXLimit, 0.0f) == false ? ConfigurableJointMotion.Limited : ConfigurableJointMotion.Locked;
		joint.angularYMotion    = Mathf.Approximately(LinkJointAngularYLimit, 0.0f) == false ? ConfigurableJointMotion.Limited : ConfigurableJointMotion.Locked;
		joint.angularZMotion    = Mathf.Approximately(LinkJointAngularZLimit, 0.0f) == false ? ConfigurableJointMotion.Limited : ConfigurableJointMotion.Locked;

		jointLimit.limit        = -LinkJointAngularXLimit;
		joint.lowAngularXLimit  = jointLimit;

		jointLimit.limit        = LinkJointAngularXLimit;
		joint.highAngularXLimit = jointLimit;

        jointLimit.limit        = LinkJointAngularYLimit;
		joint.angularYLimit     = jointLimit;

        jointLimit.limit        = LinkJointAngularZLimit;
		joint.angularZLimit     = jointLimit;

        joint.angularXDrive     = jointDrive;
		joint.angularYZDrive    = jointDrive;
/*
        joint.projectionMode     = JointProjectionMode.PositionAndRotation;
        joint.projectionDistance = 0.1f;
        joint.projectionAngle    = 0.1f;*/
    }
Example #25
0
 private extern void get_slerpDrive_Injected(out JointDrive ret);
		private extern void INTERNAL_set_angularYZDrive(ref JointDrive value);
Example #27
0
 private extern void get_angularYZDrive_Injected(out JointDrive ret);
Example #28
0
 private extern void set_angularYZDrive_Injected(ref JointDrive value);
 private void INTERNAL_set_angularXDrive(ref JointDrive value);
 private void INTERNAL_get_angularXDrive(out JointDrive value);
 private void INTERNAL_set_zDrive(ref JointDrive value);
Example #32
0
    protected bool setupJoints()
    {
        if (!gotOrig)
        {
            if ((rotate_model != "") && (transform.FindChild("model").FindChild(rotate_model) != null))
            {
                origRotation = transform.FindChild("model").FindChild(rotate_model).localRotation;
            }
            if (translateJoint)
            {
                origTranslation = transform.localPosition;
            }
            else if ((translate_model != "") && (transform.FindChild("model").FindChild(translate_model) != null))
            {
                origTranslation = transform.FindChild("model").FindChild(translate_model).localPosition;
            }
            if (rotateJoint || translateJoint)
            {
                if (attachJoint != null)
                {
                    GameObject.Destroy(attachJoint);
                    ConfigurableJoint newJoint = gameObject.AddComponent<ConfigurableJoint>();
                    newJoint.breakForce = breakingForce;
                    newJoint.breakTorque = breakingTorque;
                    newJoint.axis = rotateJoint ? rotateAxis : translateAxis;
                    newJoint.secondaryAxis = (newJoint.axis == Vector3.up) ? Vector3.forward : Vector3.up;
                    SoftJointLimit spring = new SoftJointLimit();
                    spring.limit = 0;
                    spring.damper = jointDamping;
                    spring.spring = jointSpring;
                    if (translateJoint)
                    {
                        newJoint.xMotion = ConfigurableJointMotion.Free;
                        newJoint.yMotion = ConfigurableJointMotion.Free;
                        newJoint.zMotion = ConfigurableJointMotion.Free;
                        //newJoint.linearLimit = spring;
                        JointDrive drv = new JointDrive();
                        drv.mode = JointDriveMode.PositionAndVelocity;
                        drv.positionSpring = 1e20F;
                        drv.positionDamper = 0;
                        drv.maximumForce = 1e20F;
                        newJoint.xDrive = newJoint.yDrive = newJoint.zDrive = drv;
                    }
                    else
                    {
                        newJoint.xMotion = ConfigurableJointMotion.Locked;
                        newJoint.yMotion = ConfigurableJointMotion.Locked;
                        newJoint.zMotion = ConfigurableJointMotion.Locked;
                    }
                    if (rotateJoint)
                    {
                        newJoint.angularXMotion = ConfigurableJointMotion.Limited;
                        newJoint.lowAngularXLimit = newJoint.highAngularXLimit = spring;
                    }
                    else
                    {
                        newJoint.angularXMotion = ConfigurableJointMotion.Locked;
                    }
                    newJoint.angularYMotion = ConfigurableJointMotion.Locked;
                    newJoint.angularZMotion = ConfigurableJointMotion.Locked;
                    //newJoint.anchor = rotateJoint ? rotatePivot : origTranslation;
                    newJoint.anchor = rotateJoint ? rotatePivot : Vector3.zero;

                    newJoint.projectionMode = JointProjectionMode.PositionAndRotation;
                    newJoint.projectionDistance = 0;
                    newJoint.projectionAngle = 0;

                    newJoint.connectedBody = parent.Rigidbody;
                    attachJoint = newJoint;
                    gotOrig = true;
                    return true;
                }
            }
            else
            {
                gotOrig = true;
                return true;
            }
        }
        return false;
    }
Example #33
0
 private extern void set_slerpDrive_Injected(ref JointDrive value);
 private void INTERNAL_get_zDrive(out JointDrive value);
Example #35
0
        public bool SetupJoints()
        {
            if (!GotOrig)
            {
                // remove for less spam in editor
                //print("setupJoints - !gotOrig");
                if (rotateJoint || translateJoint)
                {
                    if (part.attachJoint != null)
                    {
                        // Catch reversed joint
                        // Maybe there is a best way to do it?
                        if (transform.position != part.attachJoint.Joint.connectedBody.transform.position)
                        {
                            joint = part.attachJoint.Joint.connectedBody.gameObject.AddComponent<ConfigurableJoint>();
                            joint.connectedBody = part.attachJoint.Joint.rigidbody;
                        }
                        else
                        {
                            joint = part.attachJoint.Joint.rigidbody.gameObject.AddComponent<ConfigurableJoint>();
                            joint.connectedBody = part.attachJoint.Joint.connectedBody;
                        }

                        joint.breakForce = 1e15f;
                        joint.breakTorque = 1e15f;
                        // And to default joint
                        part.attachJoint.Joint.breakForce = 1e15f;
                        part.attachJoint.Joint.breakTorque = 1e15f;
                        part.attachJoint.SetBreakingForces(1e15f, 1e15f);

                        // lock all movement by default
                        joint.xMotion = ConfigurableJointMotion.Locked;
                        joint.yMotion = ConfigurableJointMotion.Locked;
                        joint.zMotion = ConfigurableJointMotion.Locked;
                        joint.angularXMotion = ConfigurableJointMotion.Locked;
                        joint.angularYMotion = ConfigurableJointMotion.Locked;
                        joint.angularZMotion = ConfigurableJointMotion.Locked;

                        joint.projectionDistance = 0f;
                        joint.projectionAngle = 0f;
                        joint.projectionMode = JointProjectionMode.PositionAndRotation;

                        // Copy drives
                        joint.linearLimit = part.attachJoint.Joint.linearLimit;
                        joint.lowAngularXLimit = part.attachJoint.Joint.lowAngularXLimit;
                        joint.highAngularXLimit = part.attachJoint.Joint.highAngularXLimit;
                        joint.angularXDrive = part.attachJoint.Joint.angularXDrive;
                        joint.angularYZDrive = part.attachJoint.Joint.angularYZDrive;
                        joint.xDrive = part.attachJoint.Joint.xDrive;
                        joint.yDrive = part.attachJoint.Joint.yDrive;
                        joint.zDrive = part.attachJoint.Joint.zDrive;

                        // Set anchor position
                        joint.anchor =
                            joint.rigidbody.transform.InverseTransformPoint(joint.connectedBody.transform.position);
                        joint.connectedAnchor = Vector3.zero;

                        // Set correct axis
                        joint.axis =
                            joint.rigidbody.transform.InverseTransformDirection(joint.connectedBody.transform.right);
                        joint.secondaryAxis =
                            joint.rigidbody.transform.InverseTransformDirection(joint.connectedBody.transform.up);


                        if (translateJoint)
                        {
                            joint.xMotion = ConfigurableJointMotion.Free;
                            joint.yMotion = ConfigurableJointMotion.Free;
                            joint.zMotion = ConfigurableJointMotion.Free;
                        }

                        if (rotateJoint)
                        {
                            //Docking washer is broken currently?
                            joint.rotationDriveMode = RotationDriveMode.XYAndZ;
                            joint.angularXMotion = ConfigurableJointMotion.Free;
                            joint.angularYMotion = ConfigurableJointMotion.Free;
                            joint.angularZMotion = ConfigurableJointMotion.Free;

                            // Docking washer test
                            if (jointSpring > 0)
                            {
                                if (rotateAxis == Vector3.right || rotateAxis == Vector3.left)
                                {
                                    JointDrive drv = joint.angularXDrive;
                                    drv.positionSpring = jointSpring;
                                    joint.angularXDrive = drv;

                                    joint.angularYMotion = ConfigurableJointMotion.Locked;
                                    joint.angularZMotion = ConfigurableJointMotion.Locked;
                                }
                                else
                                {
                                    JointDrive drv = joint.angularYZDrive;
                                    drv.positionSpring = jointSpring;
                                    joint.angularYZDrive = drv;

                                    joint.angularXMotion = ConfigurableJointMotion.Locked;
                                    joint.angularZMotion = ConfigurableJointMotion.Locked;
                                }
                            }
                        }

                        // Reset default joint drives
                        var resetDrv = new JointDrive
                        {
                            mode = JointDriveMode.PositionAndVelocity,
                            positionSpring = 0,
                            positionDamper = 0,
                            maximumForce = 0
                        };

                        part.attachJoint.Joint.angularXDrive = resetDrv;
                        part.attachJoint.Joint.angularYZDrive = resetDrv;
                        part.attachJoint.Joint.xDrive = resetDrv;
                        part.attachJoint.Joint.yDrive = resetDrv;
                        part.attachJoint.Joint.zDrive = resetDrv;

                        GotOrig = true;
                        return true;
                    }
                    return false;
                }

                GotOrig = true;
                return true;
            }
            return false;
        }
		private extern void INTERNAL_get_slerpDrive(out JointDrive value);
        /// <summary>
        /// Removes the muscle with the specified joint and all muscles connected to it from PuppetMaster management. This will not destroy the body part/prop, but just release it from following the target.
        /// If you call RemoveMuscleRecursive on an upper arm muscle, the entire arm will be disconnected from the rest of the body.
        /// If attachTarget is true, the target Transform of the first muscle will be parented to the disconnected limb.
        /// This method allocates some memory, avoid using it each frame.
        /// </summary>
        public void RemoveMuscleRecursive(ConfigurableJoint joint, bool attachTarget)
        {
            if (!CheckIfInitiated()) return;

            if (joint == null) {
                Debug.LogWarning("RemoveMuscleRecursive was called with a null 'joint' reference.", transform);
                return;
            }

            if (!ContainsJoint(joint)) {
                Debug.LogWarning("No Muscle with the specified joint was found, can not remove muscle.", transform);
                return;
            }

            int index = GetMuscleIndex(joint);
            Muscle[] newMuscles = new Muscle[muscles.Length - (muscles[index].childIndexes.Length + 1)];

            int added = 0;
            for (int i = 0; i < muscles.Length; i++) {
                if (i != index && !muscles[index].childFlags[i]) {
                    newMuscles[added] = muscles[i];
                    added ++;
                } else {
                    if (muscles[i].broadcaster != null) Destroy(muscles[i].broadcaster);
                }
            }

            muscles[index].joint.connectedBody = null;

            muscles[index].joint.targetRotation = Quaternion.identity;
            JointDrive j = new JointDrive();
            j.positionSpring = 0f;
            #if UNITY_5_2
            j.mode = JointDriveMode.None;
            #endif
            muscles[index].joint.slerpDrive = j;
            muscles[index].joint.xMotion = ConfigurableJointMotion.Free;
            muscles[index].joint.yMotion = ConfigurableJointMotion.Free;
            muscles[index].joint.zMotion = ConfigurableJointMotion.Free;
            muscles[index].joint.angularXMotion = ConfigurableJointMotion.Free;
            muscles[index].joint.angularYMotion = ConfigurableJointMotion.Free;
            muscles[index].joint.angularZMotion = ConfigurableJointMotion.Free;

            muscles[index].transform.parent = null;

            if (attachTarget) {
                muscles[index].target.parent = muscles[index].transform;
                muscles[index].target.position = muscles[index].transform.position;
                muscles[index].target.rotation = muscles[index].transform.rotation * muscles[index].targetRotationRelative;
            }

            muscles = newMuscles;

            UpdateHierarchies();
        }
Example #38
0
        /// <summary>
        /// ă‚žăƒ§ă‚€ăƒłăƒˆă«ă°ă­ăȘă©ăźăƒ‘ăƒ©ăƒĄăƒŒă‚żă‚’èš­ćźšă™ă‚‹
        /// </summary>
        /// <param name='joint'>PMXç”šă‚žăƒ§ă‚€ăƒłăƒˆăƒ‡ăƒŒă‚ż</param>
        /// <param name='conf'>Unityç”šă‚žăƒ§ă‚€ăƒłăƒˆ</param>
        void SetDrive(PMXFormat.Joint joint, ConfigurableJoint conf)
        {
            JointDrive drive;

            // Position
            if (joint.spring_position.x != 0.0f) {
                drive = new JointDrive();
                drive.positionSpring = joint.spring_position.x * scale_;
                conf.xDrive = drive;
            }
            if (joint.spring_position.y != 0.0f) {
                drive = new JointDrive();
                drive.positionSpring = joint.spring_position.y * scale_;
                conf.yDrive = drive;
            }
            if (joint.spring_position.z != 0.0f) {
                drive = new JointDrive();
                drive.positionSpring = joint.spring_position.z * scale_;
                conf.zDrive = drive;
            }

            // Angular
            if (joint.spring_rotation.x != 0.0f) {
                drive = new JointDrive();
                drive.mode = JointDriveMode.PositionAndVelocity;
                drive.positionSpring = joint.spring_rotation.x;
                conf.angularXDrive = drive;
            }
            if (joint.spring_rotation.y != 0.0f || joint.spring_rotation.z != 0.0f) {
                drive = new JointDrive();
                drive.mode = JointDriveMode.PositionAndVelocity;
                drive.positionSpring = (joint.spring_rotation.y + joint.spring_rotation.z) * 0.5f;
                conf.angularYZDrive = drive;
            }
        }
        public void LoadBoomHead()
        {
            if (savedSectionsLocalPos.Count > 0) {
              //Reset section(s) to org pos
              foreach (KeyValuePair<int, SectionInfo> section in sections) {
            section.Value.transform.position = part.transform.TransformPoint(section.Value.orgLocalPos);
              }
            }

            KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) Create physical object...");
            boomHeadPhysicModule = this.part.gameObject.GetComponent<KASModulePhysicChild>();
            if (!boomHeadPhysicModule) {
              KAS_Shared.DebugLog(
              "LoadBoomHead(TelescopicArm) - KASModulePhysicChild do not exist, adding it...");
              boomHeadPhysicModule = this.part.gameObject.AddComponent<KASModulePhysicChild>();
            }
            boomHeadPhysicModule.StartPhysics(sections[0].transform.gameObject, boomHeadMass);

            orgBoomHeadMass = this.part.mass;
            float newMass = this.part.mass - boomHeadMass;
            if (newMass > 0) {
              this.part.mass = newMass;
            } else {
              KAS_Shared.DebugWarning(
              "LoadBoomHead(TelescopicArm) - Mass of the boom head is greater than the part !");
            }

            KAS_Shared.DebugLog("LoadRotor - Disable collision...");
            disableSectionCollision();

            KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Create configurable joint...");
            slideJoint = this.part.gameObject.AddComponent<ConfigurableJoint>();
            slideJoint.connectedBody = sections[0].transform.GetComponent<Rigidbody>();
            slideJoint.axis = Vector3.zero;
            slideJoint.secondaryAxis = Vector3.zero;
            slideJoint.breakForce = breakForce;
            slideJoint.breakTorque = breakForce;
            slideJoint.angularXMotion = ConfigurableJointMotion.Locked;
            slideJoint.angularYMotion = ConfigurableJointMotion.Locked;
            slideJoint.angularZMotion = ConfigurableJointMotion.Locked;
            slideJoint.xMotion = ConfigurableJointMotion.Locked;
            slideJoint.yMotion = ConfigurableJointMotion.Locked;
            slideJoint.zMotion = ConfigurableJointMotion.Locked;

            if (direction.x != 0) {
              slideJoint.xMotion = ConfigurableJointMotion.Limited;
              driveWay = direction.x;
              KAS_Shared.DebugLog(
              "LoadBoomHead(TelescopicArm) - Direction set to x axis with driveWay set to : "
              + driveWay);
            } else if (direction.y != 0) {
              slideJoint.yMotion = ConfigurableJointMotion.Limited;
              driveWay = direction.y;
              KAS_Shared.DebugLog(
              "LoadBoomHead(TelescopicArm) - Direction set to y axis with driveWay set to : "
              + driveWay);
            } else if (direction.z != 0) {
              slideJoint.zMotion = ConfigurableJointMotion.Limited;
              driveWay = direction.z;
              KAS_Shared.DebugLog(
              "LoadBoomHead(TelescopicArm) - Direction set to z axis with driveWay set to : "
              + driveWay);
            }

            JointDrive drv = new JointDrive();
            drv.mode = JointDriveMode.PositionAndVelocity;
            drv.positionSpring = driveSpring;
            drv.positionDamper = driveDamper;
            drv.maximumForce = driveForce;
            slideJoint.xDrive = slideJoint.yDrive = slideJoint.zDrive = drv;

            var jointLimit = new SoftJointLimit();
            jointLimit.limit = sectionTotalLenght;
            jointLimit.bounciness = 1;
            slideJoint.linearLimit = jointLimit;
            slideJoint.linearLimitSpring = new SoftJointLimitSpring() {
              damper = 200,
              spring = 1000
            };

            if (savedSectionsLocalPos.Count > 0) {
              KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Re-set section position from save");
              float sumLenght = 0;
              foreach (KeyValuePair<int, SectionInfo> section in sections) {
            KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Move section " + section.Key
                            + " to local position : " + section.Value.savedLocalPos);
            section.Value.transform.position =
            part.transform.TransformPoint(section.Value.savedLocalPos);
            sumLenght += section.Value.lenght;
            if (headPos > sumLenght) {
              KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Parent section "
                              + sections[section.Key + 1].transform.name + " to : "
                              + section.Value.transform.name);
              sections[section.Key + 1].transform.parent = section.Value.transform;
            }
              }
            }

            // Get boom head attach nodes
            attachNodes.Clear();
            ConfigNode node = KAS_Shared.GetBaseConfigNode(this);
            List<string> attachNodesSt = new List<string>(node.GetValues("attachNode"));
            foreach (String anString in attachNodesSt) {
              AttachNode an = this.part.findAttachNode(anString);
              if (an != null) {
            KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Boom head attach node added : " + an.id);
            attachNodes.Add(an);
            if (an.attachedPart) {
              KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Setting boom head joint on : "
                              + an.attachedPart.partInfo.title);
              KAS_Shared.RemoveFixedJointBetween(this.part, an.attachedPart);
              KAS_Shared.RemoveHingeJointBetween(this.part, an.attachedPart);
              FixedJoint fjnt = an.attachedPart.gameObject.AddComponent<FixedJoint>();
              fjnt.connectedBody = sections[0].transform.GetComponent<Rigidbody>();
              fixedJnts.Add(fjnt);
            }
              }
            }
            SetTargetPos(targetPos);
            boomHeadLoaded = true;
        }
Example #40
0
    // TODO: Limbs should be made into a better tree structure, not this
    // 				list of lists rubbish
    private void setupLimbs()
    {
        int num_branches = chromosome.getBranchCount();
        chromosome.setNumBranches(num_branches);

        for (int i=0; i<num_branches; i++)
        {
            limbs = chromosome.getLimbs(i);
            List<GameObject> actual_limbs = new List<GameObject>();

            int recurrences = chromosome.num_recurrences[i];
            for (int j=0; j<recurrences; ++j) {
                GameObject limb = GameObject.CreatePrimitive(PrimitiveType.Cube);
                limb.layer = LayerMask.NameToLayer("Creature");
                limb.name = "limb_"+i+"_"+j;
                limb.transform.parent = _t;
                actual_limbs.Add(limb);
                Limb limb_script = limb.AddComponent<Limb>();

                ArrayList attributes = (ArrayList) limbs[j];
                limb_script.setScale( (Vector3) attributes[1] );
                limb_script.setColour( (Color) chromosome.getLimbColour());

                if(j == 0) {
                    limb_script.setPosition( (Vector3) attributes[0] );
                    limb.transform.LookAt(root.transform);
                } else {
                    limb_script.setPosition( actual_limbs[j-1].transform.localPosition );
                    limb.transform.LookAt(root.transform);
                    limb.transform.Translate(0,0,-actual_limbs[j-1].transform.localScale.z);
                }

                limb.AddComponent<Rigidbody>();
                limb.AddComponent<BoxCollider>();
                limb.GetComponent<Collider>().material = (PhysicMaterial)Resources.Load("Physics Materials/Creature");

                ConfigurableJoint joint = limb.AddComponent<ConfigurableJoint>();
                //joint.configuredInWorldSpace = true;
                joint.axis = new Vector3(0.5F, 0F, 0F);
                joint.anchor = new Vector3(0F, 0F, 0.5F);
                if(j == 0) {
                    joint.connectedBody = root.GetComponent<Rigidbody>();
                } else {
                    joint.connectedBody = actual_limbs[j-1].GetComponent<Rigidbody>();
                }
                limb.GetComponent<Rigidbody>().drag = 1F;

                joints.Add(joint);

                joint.xMotion = ConfigurableJointMotion.Locked;
                joint.yMotion = ConfigurableJointMotion.Locked;
                joint.zMotion = ConfigurableJointMotion.Locked;

                joint.angularXMotion = ConfigurableJointMotion.Free;
                joint.angularYMotion = ConfigurableJointMotion.Free;
                joint.angularZMotion = ConfigurableJointMotion.Free;

                JointDrive angXDrive = new JointDrive();
                angXDrive.mode = JointDriveMode.Position;
                angXDrive.positionSpring = 7F;
                angXDrive.maximumForce = 100000000F;
                joint.angularXDrive = angXDrive;
                joint.angularYZDrive = angXDrive;

                limb.GetComponent<Rigidbody>().SetDensity(1F);
            }
        }
    }
 private void INTERNAL_set_angularXDrive(ref JointDrive value);
Example #42
0
	void PlaceJointConnections()
	{	
		if(Application.isPlaying)
			jointParent = new GameObject("Rope");
		else
			jointParent = new GameObject("TempRope");
		
		jointParent.transform.position = ropeEnd.transform.position;
		jointParent.transform.LookAt(transform.position);
		
		GameObject tJC;
		ConfigurableJoint tCJ;
		SoftJointLimit sjl;
		JointDrive jd;
		CapsuleCollider cc;
		SphereCollider sc;
		
		for(int i = 0; i <= linkCount; i++)
		{
			tJC = new GameObject("Connection_"+i.ToString());
			tJC.transform.position = ropeEnd.transform.position + (jointHeading * jointGap * i);
			tJC.transform.LookAt(transform.position + jointHeading);
			
			tJC.transform.parent = jointParent.transform;
			tJC.AddComponent<Rigidbody>();
			tJC.rigidbody.drag = jointDrag;
			tJC.rigidbody.useGravity = jointsHaveGravity;
			
			switch(constraintPlane)
			{
				case ConstraintPlane.X_Y:
					tJC.rigidbody.constraints = RigidbodyConstraints.FreezePositionZ;
					break;
				case ConstraintPlane.Y_Z:
					tJC.rigidbody.constraints = RigidbodyConstraints.FreezePositionX;
					break;
				case ConstraintPlane.Z_X:
					tJC.rigidbody.constraints = RigidbodyConstraints.FreezePositionY;
					break;
				default:
					break;
			}
			
			if(includeSphereColliders)
			{
				sc = tJC.AddComponent<SphereCollider>();
				sc.radius = ropeRadius;
				sc.material = ropePhysicMaterial;
			}
			
			if(includeCapsuleColliders && i<linkCount)
			{
				cc = tJC.AddComponent<CapsuleCollider>();
				cc.center = new Vector3(0,0,jointGap/2);
				cc.height = jointGap * 1.33f;
				cc.direction = 2;
				cc.radius = ropeRadius;
				cc.material = ropePhysicMaterial;
			}
			
			tCJ = tJC.AddComponent<ConfigurableJoint>();
			try{tCJ.connectedBody = jointConnections[i-1].rigidbody; }catch{ tCJ.connectedBody = ropeEnd.rigidbody; }
			
			//tCJ.swingAxis = new Vector3(1,1,1);
			tCJ.xMotion = ConfigurableJointMotion.Locked;
			tCJ.yMotion = ConfigurableJointMotion.Locked;
			tCJ.zMotion = ConfigurableJointMotion.Locked;
			
			tCJ.angularZMotion = ConfigurableJointMotion.Limited;
			sjl = new SoftJointLimit(){ limit = MinMaxTwist };
			tCJ.angularZLimit = sjl;
		
			
			jd = new JointDrive() { mode = JointDriveMode.Position };
			tCJ.xDrive = jd;
			tCJ.yDrive = jd;
			tCJ.zDrive = jd; 
			
			tCJ.projectionMode = JointProjectionMode.PositionOnly;
			tCJ.projectionDistance = 0.1f;
			
			
			if(i == linkCount)
			{
				tCJ = tJC.AddComponent<ConfigurableJoint>();
					
				tCJ.connectedBody = rigidbody;
				tCJ.xMotion = ConfigurableJointMotion.Locked;
				tCJ.yMotion = ConfigurableJointMotion.Locked;
				tCJ.zMotion = ConfigurableJointMotion.Locked;
				
				tCJ.angularZMotion = ConfigurableJointMotion.Limited;
				sjl = new SoftJointLimit(){ limit = MinMaxTwist };
				tCJ.angularZLimit = sjl;
				
				jd = new JointDrive() { mode = JointDriveMode.Position };
				tCJ.xDrive = jd;
				tCJ.yDrive = jd;
				tCJ.zDrive = jd; 
				
				tCJ.projectionMode = JointProjectionMode.PositionOnly;
				tCJ.projectionDistance = 0.1f;	
			}
			
			jointConnections.Add(tJC);
		}
	}
 static public int get_maximumForce(IntPtr l)
 {
     UnityEngine.JointDrive o = (UnityEngine.JointDrive)checkSelf(l);
     pushValue(l, o.maximumForce);
     return(1);
 }
Example #44
0
 private extern void INTERNAL_set_angularYZDrive(ref JointDrive value);
Example #45
0
 private void INTERNAL_get_angularYZDrive(out JointDrive value)
 {
     throw new NotImplementedException("ăȘă«ă“ă‚Œ");
 }
Example #46
0
 private extern void INTERNAL_set_slerpDrive(ref JointDrive value);
 private void INTERNAL_get_angularXDrive(out JointDrive value);
    void RedrawRope()
    {
        if(prefab != null)
        {
            if( linkCount >= jointConnections.Count ) {
                int i = linkCount;
                GameObject tJC = new GameObject("Connection_"+i.ToString());
                //tJC.transform.position = ropeEnd.transform.position + (jointHeading * linkLength * i);
                //tJC.transform.LookAt(transform.position);

                if( jointParent == null ) {
                    tJC.transform.parent = GameObject.Find( "Rope" ).transform;
                }
                else {
                    tJC.transform.parent = jointParent.transform;
                }
                tJC.AddComponent<Rigidbody>();
                //tJC.rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
                tJC.rigidbody.angularDrag = 0;

                ConfigurableJoint tCJ = tJC.AddComponent<ConfigurableJoint>();
                tCJ.configuredInWorldSpace = true;
                try{
                    tCJ.connectedBody = jointConnections[i-2].rigidbody;
                    jointConnections[i-1].GetComponent<ConfigurableJoint>().connectedBody = rigidbody;
                    jointConnections.Insert( i-1, tJC );
                }
                catch{
                    tCJ.connectedBody = ropeEnd.rigidbody;
                }

                //tCJ.swingAxis = new Vector3(1,1,1);
                tCJ.xMotion = ConfigurableJointMotion.Locked;
                tCJ.yMotion = ConfigurableJointMotion.Locked;
                tCJ.zMotion = ConfigurableJointMotion.Locked;

                tCJ.angularXMotion = ConfigurableJointMotion.Locked;
                tCJ.angularYMotion = ConfigurableJointMotion.Locked;
                tCJ.angularZMotion = ConfigurableJointMotion.Locked;

                JointDrive jd = new JointDrive() { mode = JointDriveMode.Position };
                tCJ.xDrive = jd;
                tCJ.yDrive = jd;
                tCJ.zDrive = jd;

                Debug.Log( "insertion" );

                //NewJoint( i );
                //AddPrefab( i );
            }

            //Debug.Log( "jointConnections: " + jointConnections.Count );
            for(int i = 0; i < linkCount; i++)
            {

                //jointConnections[i].transform.LookAt( ropeEnd.transform.position );
                try{
                    jointConnections[i].transform.position = Vector3.Lerp( ropeEnd.transform.position, transform.position, (float)i/(float)50.0f );
                    jointConnections[i].transform.LookAt( jointConnections[i-1].transform.position );
                }
                catch {
                }
                //tPrefab.transform.position = jointConnections[i].transform.position + (jointHeading/2 * jointGap);
                //tPrefab.transform.parent = jointConnections[i].transform;
                //tPrefab.transform.parent.LookAt(transform.position);
                //tPrefab.transform.Rotate(0,0, altRotation * i);
                //tPrefab.transform.Rotate (new Vector3(0, 1, 0), 90.0f);
                //tPrefab.transform.localScale *= scale;

                //var renderer = (Renderer) tPrefab.GetComponentInChildren (typeof(Renderer));
                //linkLength = renderer.bounds.size.z;
                //var mesh = (Mesh) tPrefab.GetComponentInChildren (typeof(Mesh));
            }
            if( jointConnections.Count > 0 )
                jointConnections[0].transform.LookAt( transform.position );
        }
    }
 static public int get_positionDamper(IntPtr l)
 {
     UnityEngine.JointDrive o = (UnityEngine.JointDrive)checkSelf(l);
     pushValue(l, o.positionDamper);
     return(1);
 }
Example #50
0
    protected bool setupJoints()
    {
        if (!gotOrig)
        {
            print("setupJoints - !gotOrig");

            if ((rotate_model != "") && (transform.FindChild("model").FindChild(rotate_model) != null))
            {
                //origRotation = transform.FindChild("model").FindChild(rotate_model).localRotation;
            }
            else if ((translate_model != "") && (transform.FindChild("model").FindChild(translate_model) != null))
            {
                //origTranslation = transform.FindChild("model").FindChild(translate_model).localPosition;
            }

            if (translateJoint)
            {
                //origTranslation = transform.localPosition;
            }

            if (rotateJoint || translateJoint)
            {
                if (attachJoint != null)
                {
                    // Catch reversed joint
                    // Maybe there is a best way to do it?
                    if (transform.position != attachJoint.Joint.connectedBody.transform.position)
                    {
                        joint = attachJoint.Joint.connectedBody.gameObject.AddComponent<ConfigurableJoint>();
                        joint.connectedBody = attachJoint.Joint.rigidbody;
                    }
                    else
                    {
                        joint = attachJoint.Joint.rigidbody.gameObject.AddComponent<ConfigurableJoint>();
                        joint.connectedBody = attachJoint.Joint.connectedBody;
                    }

                    // Assign break forces
                    joint.breakForce = breakingForce;
                    joint.breakTorque = breakingTorque;
                    // And to default joint
                    attachJoint.Joint.breakForce = breakingForce;
                    attachJoint.Joint.breakTorque = breakingTorque;

                    // lock all movement by default
                    joint.xMotion = ConfigurableJointMotion.Locked;
                    joint.yMotion = ConfigurableJointMotion.Locked;
                    joint.zMotion = ConfigurableJointMotion.Locked;
                    joint.angularXMotion = ConfigurableJointMotion.Locked;
                    joint.angularYMotion = ConfigurableJointMotion.Locked;
                    joint.angularZMotion = ConfigurableJointMotion.Locked;

                    joint.projectionDistance = 0f;
                    joint.projectionAngle = 0f;
                    joint.projectionMode = JointProjectionMode.PositionAndRotation;

                    // Copy drives
                    joint.linearLimit = attachJoint.Joint.linearLimit;
                    joint.lowAngularXLimit = attachJoint.Joint.lowAngularXLimit;
                    joint.highAngularXLimit = attachJoint.Joint.highAngularXLimit;
                    joint.angularXDrive = attachJoint.Joint.angularXDrive;
                    joint.angularYZDrive = attachJoint.Joint.angularYZDrive;
                    joint.xDrive = attachJoint.Joint.xDrive;
                    joint.yDrive = attachJoint.Joint.yDrive;
                    joint.zDrive = attachJoint.Joint.zDrive;

                    // Set anchor position
                    joint.anchor = joint.rigidbody.transform.InverseTransformPoint(joint.connectedBody.transform.position);
                    joint.connectedAnchor = Vector3.zero;

                    // Set correct axis
                    joint.axis = joint.rigidbody.transform.InverseTransformDirection(joint.connectedBody.transform.right);
                    joint.secondaryAxis = joint.rigidbody.transform.InverseTransformDirection(joint.connectedBody.transform.up);

                    if (translateJoint)
                    {
                        joint.xMotion = ConfigurableJointMotion.Free;
                        joint.yMotion = ConfigurableJointMotion.Free;
                        joint.zMotion = ConfigurableJointMotion.Free;
                    }

                    if (rotateJoint)
                    {
                        //Docking washer is broken currently?
                        joint.rotationDriveMode = RotationDriveMode.XYAndZ;
                        joint.angularXMotion = ConfigurableJointMotion.Free;
                        joint.angularYMotion = ConfigurableJointMotion.Free;
                        joint.angularZMotion = ConfigurableJointMotion.Free;

                        // Docking washer test
                        if (jointSpring > 0)
                        {
                            if (rotateAxis == Vector3.right || rotateAxis == Vector3.left)
                            {
                                JointDrive drv = joint.angularXDrive;
                                drv.positionSpring = jointSpring;
                                joint.angularXDrive = drv;

                                joint.angularYMotion = ConfigurableJointMotion.Locked;
                                joint.angularZMotion = ConfigurableJointMotion.Locked;
                            }
                            else
                            {
                                JointDrive drv = joint.angularYZDrive;
                                drv.positionSpring = jointSpring;
                                joint.angularYZDrive = drv;

                                joint.angularXMotion = ConfigurableJointMotion.Locked;
                                joint.angularZMotion = ConfigurableJointMotion.Locked;
                            }
                        }
                    }

                    /*
                    if (translateJoint)
                    {
                        if (this.attachMode == AttachModes.STACK)
                        {
                            attachJoint.Joint.anchor -= this.attachJoint.TgtAnchor;
                            attachJoint.Joint.connectedAnchor -= joint.connectedAnchor;
                        }
                        else
                        {
                            //SURFACE ATTACHMENTS WORK WITHOUT ANY CHANGES (most of the time)!!!!
                            //Don't do a damn thing here!
                        }
                    }

                    if (rotateJoint)
                    {
                        //Stack attach mode works
                        if (this.attachMode == AttachModes.STACK)
                        {
                            attachJoint.Joint.anchor -= joint.connectedAnchor;
                            attachJoint.Joint.connectedAnchor -= joint.connectedAnchor;
                        }
                        else
                        {
                            //this corrects the orientation for surface attachments, sometimes it works, sometimes it doesn't
                            attachJoint.Joint.anchor -= joint.axis * attachJoint.TgtAnchor.magnitude;
                            attachJoint.Joint.connectedAnchor -= joint.connectedAnchor;
                        }
                    }
                    //*/

                    // Reset default joint drives
                    JointDrive resetDrv = new JointDrive();
                    resetDrv.mode = JointDriveMode.PositionAndVelocity;
                    resetDrv.positionSpring = 0;
                    resetDrv.positionDamper = 0;
                    resetDrv.maximumForce = 0;

                    attachJoint.Joint.angularXDrive = resetDrv;
                    attachJoint.Joint.angularYZDrive = resetDrv;
                    attachJoint.Joint.xDrive = resetDrv;
                    attachJoint.Joint.yDrive = resetDrv;
                    attachJoint.Joint.zDrive = resetDrv;

                    gotOrig = true;
                    return true;
                }
            }
            else
            {
                gotOrig = true;
                return true;
            }
        }
        return false;
    }
Example #51
0
 /// <summary>
 /// Technical recursive function that scans the whole armature and sets the joints mode, damper and spring based on the mass of the joint's limb
 /// </summary>
 /// <param name="varpparent">
 /// The target of the tweak
 /// </param>
 /// <param name="varpfrequency">
 /// Sampling frequency for the spring and damping
 /// </param>
 /// <param name="varpdamping">
 /// The damping value in hertz
 /// </param>
 /// <param name="varpdampfactor">
 /// The damping strength in kg/s
 /// </param>
 /// <param name="varpelasticityfactor">
 /// The elasticity in m/s
 /// </param>
 //http://developer.anscamobile.com/content/game-edition-physics-joints
 private void metnormalizerigidity(Transform varpparent, float varpfrequency, float varpdamping, float varpdampfactor, float varpelasticityfactor)
 {
     CharacterJoint varcurrentjoint = varpparent.GetComponent<CharacterJoint>();
     if (varcurrentjoint != null) {
         metprint("Normalizing joint " + varpparent + " rigidity",0);
         JointDrive varcurrentjointdrive = new JointDrive();
         varcurrentjointdrive.mode = JointDriveMode.Position;
         varcurrentjointdrive.positionDamper = varpdampfactor * (varrigidity/varpfrequency) * varpdamping * metlimbmass(varpparent);
         varcurrentjointdrive.positionSpring = varpelasticityfactor * (varrigidity/varpfrequency) * varpfrequency * metlimbmass(varpparent);
         varcurrentjoint.rotationDrive = varcurrentjointdrive;
         foreach (Transform varchild in varpparent) {
             metnormalizerigidity(varchild, varpfrequency, varpdamping, varpdampfactor,varpelasticityfactor);
         }
     }
 }
Example #52
0
 private void INTERNAL_set_slerpDrive(ref JointDrive value)
 {
     throw new NotImplementedException("ăȘă«ă“ă‚Œ");
 }
		private extern void INTERNAL_get_angularYZDrive(out JointDrive value);
Example #54
0
    protected bool setupJoints()
    {
        if (!gotOrig)
        {
            print("setupJoints - !gotOrig");
            if ((rotate_model != "") && (transform.FindChild("model").FindChild(rotate_model) != null))
            {
                origRotation = transform.FindChild("model").FindChild(rotate_model).localRotation;
            }
            else if ((translate_model != "") && (transform.FindChild("model").FindChild(translate_model) != null))
            {
                origTranslation = transform.FindChild("model").FindChild(translate_model).localPosition;
            }
            if (translateJoint)
            {
                origTranslation = transform.localPosition;
            }
            if (rotateJoint || translateJoint)
            {
                if (attachJoint != null)
                {
                    attachJoint.Joint.xMotion = ConfigurableJointMotion.Locked;
                    attachJoint.Joint.yMotion = ConfigurableJointMotion.Locked;
                    attachJoint.Joint.zMotion = ConfigurableJointMotion.Locked;

                    attachJoint.Joint.angularXMotion = ConfigurableJointMotion.Locked;
                    attachJoint.Joint.angularYMotion = ConfigurableJointMotion.Locked;
                    attachJoint.Joint.angularZMotion = ConfigurableJointMotion.Locked;

                    attachJoint.Joint.projectionMode = JointProjectionMode.PositionAndRotation;
                    attachJoint.Joint.projectionDistance = 0;
                    attachJoint.Joint.projectionAngle = 0;

                    if (translateJoint)
                    {
                        attachJoint.Joint.xMotion = ConfigurableJointMotion.Free;
                        attachJoint.Joint.yMotion = ConfigurableJointMotion.Free;
                        attachJoint.Joint.zMotion = ConfigurableJointMotion.Free;

                        JointDrive drv = new JointDrive();
                        drv.mode = JointDriveMode.PositionAndVelocity;
                        drv.positionSpring = 1e20F;
                        drv.positionDamper = 0;
                        drv.maximumForce = 1e20F;
                        attachJoint.Joint.xDrive = attachJoint.Joint.yDrive = attachJoint.Joint.zDrive = drv;
                    }

                    if (rotateJoint)
                    {
                        //SoftJointLimit linLimit = new SoftJointLimit();
                        //linLimit.limit = rotateMin;
                        //linLimit.damper = jointDamping;
                        //linLimit.spring = jointSpring;

                        attachJoint.Joint.angularXMotion = ConfigurableJointMotion.Free;
                        attachJoint.Joint.angularYMotion = ConfigurableJointMotion.Free;
                        attachJoint.Joint.angularZMotion = ConfigurableJointMotion.Free;
                        //attachJoint.Joint.lowAngularXLimit = attachJoint.Joint.highAngularXLimit = linLimit;
                    }

                    attachJoint.Joint.anchor -= attachJoint.Joint.connectedAnchor;
                    attachJoint.Joint.connectedAnchor = Vector3.zero;

                    gotOrig = true;
                    return true;
                }
            }
            else
            {
                gotOrig = true;
                return true;
            }
        }
        return false;
    }
 static public int get_mode(IntPtr l)
 {
     UnityEngine.JointDrive o = (UnityEngine.JointDrive)checkSelf(l);
     pushEnum(l, (int)o.mode);
     return(1);
 }
Example #56
0
    protected virtual void InitializeJoints()
    {
        for (int i = 0; i < _objs.Length; ++i) {
            JointDrive drive = new JointDrive();
            drive.positionSpring = _config.kP * _rigs[i].mass * _objs[i].GetComponentsInChildren<Rigidbody>().Length;
            drive.positionDamper = 2 * Mathf.Sqrt(drive.positionSpring);
            drive.maximumForce = Mathf.Infinity;

            _joints[i].angularXDrive = drive;
            _joints[i].angularYZDrive = drive;
        }
    }
    void BeginPhysicalDrag()
    {
        foreach (GameObject focusObject in m_focusObjects)
        {
          // Replace any nested Rigidbodies with a master one that has pre-determined properties.

          Vector3 velocity = (focusObject.rigidbody != null) ? focusObject.rigidbody.velocity : Vector3.zero;
          Vector3 angularVelocity = (focusObject.rigidbody != null) ? focusObject.rigidbody.angularVelocity : Vector3.zero;

          foreach (Rigidbody childRb in focusObject.transform.GetComponentsInChildren<Rigidbody>())
          {
        m_rigidbodyProperties[childRb.gameObject] = new RigidbodyProperties(childRb);
        DestroyImmediate(childRb);
          }

          if (focusObject.rigidbody == null)
          {
        Rigidbody rb = focusObject.AddComponent<Rigidbody>();
        RigidbodyProperties.GetDraggingProperties().ApplyTo(rb);
        rb.velocity = velocity;
        rb.angularVelocity = angularVelocity;
          }

          // Constrain the dragged object to the stylus.
          ConfigurableJoint joint = focusObject.AddComponent<ConfigurableJoint>();
          joint.connectedBody = rigidbody;
          joint.anchor = m_contactPoint;
          joint.xMotion = ConfigurableJointMotion.Limited;
          joint.yMotion = ConfigurableJointMotion.Limited;
          joint.zMotion = ConfigurableJointMotion.Limited;
          joint.angularXMotion = ConfigurableJointMotion.Limited;
          joint.angularYMotion = ConfigurableJointMotion.Limited;
          joint.angularZMotion = ConfigurableJointMotion.Limited;
          JointDrive jointDrive = new JointDrive();
          jointDrive.mode = JointDriveMode.Position;
          jointDrive.positionSpring = 0.1f;
          jointDrive.positionDamper = 500000;
          joint.xDrive = jointDrive;
          joint.yDrive = jointDrive;
          joint.zDrive = jointDrive;
          //    joint.angularXDrive = jointDrive;
          //    joint.angularYZDrive = jointDrive;
          m_joints[focusObject] = joint;
        }

        // Clear the hover now now because Unity never gives us OnTrigger events during physical sub-assembly drag.
        if (m_focusObjects.Count > 0)
          m_stylusSelector.hoveredObject = null;
    }