The configurable joint is an extremely flexible joint giving you complete control over rotation and linear motion.

Inheritance: Joint
Exemplo n.º 1
0
	/// <summary>
	/// Physicsに移動する前のGameObjectを取得する
	/// </summary>
	private GameObject GetOriginalParent(ConfigurableJoint joint)
	{
		PhysicsManager self = (PhysicsManager)target;
		return self.connect_bone_list.Where(x=>(joint.gameObject == x.joint))
									.Select(x=>x.parent)
									.FirstOrDefault();
	}
Exemplo n.º 2
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;
	}
Exemplo n.º 3
0
    void Start()
    {
        motor = GetComponent<PlayerMotor>();
        joint = GetComponent<ConfigurableJoint>();

        SetJointSettings(jointSpring);
    }
 void Start()
 {
     this._motor = this.GetComponent<PlayerMotor>();
     this._joint = this.GetComponent<ConfigurableJoint>();
     this._animator = this.GetComponent<Animator>();
     this.SetJointSettings(this._jointSpring);
 }
Exemplo n.º 5
0
 public static void ApplyXDeltaToJointLimit(ref ConfigurableJoint joint, float delta, JointAxis jointAxis, bool low)
 {
     switch(jointAxis) {
     case JointAxis.Primary:
         if (low) {
             SoftJointLimit lowX = joint.lowAngularXLimit;
             lowX.limit += delta;
             joint.lowAngularXLimit = lowX;
         } else {
             SoftJointLimit highX = joint.highAngularXLimit;
             highX.limit -= delta;
             joint.highAngularXLimit = highX;
         }
         break;
     case JointAxis.Secondary:
         SoftJointLimit y = joint.angularYLimit;
         y.limit += delta * 0.5f;
         joint.angularYLimit = y;
         break;
     case JointAxis.Tertiary:
         SoftJointLimit z = joint.angularZLimit;
         z.limit += delta * 0.5f;
         joint.angularZLimit = z;
         break;
     }
 }
    static void SetTargetRotationInternal(ConfigurableJoint joint, Quaternion targetRotation, Quaternion startRotation, Space space)
    {
        // Calculate the rotation expressed by the joint's axis and secondary axis
        var right = joint.axis;
        var forward = Vector3.Cross (joint.axis, joint.secondaryAxis).normalized;
        var up = Vector3.Cross (forward, right).normalized;
        Quaternion worldToJointSpace = Quaternion.LookRotation (forward, up);

        // Transform into world space
        Quaternion resultRotation = Quaternion.Inverse (worldToJointSpace);

        // Counter-rotate and apply the new local rotation.
        // Joint space is the inverse of world space, so we need to invert our value
        if (space == Space.World) {
            resultRotation *= startRotation * Quaternion.Inverse (targetRotation);
        } else {
            resultRotation *= Quaternion.Inverse (targetRotation) * startRotation;
        }

        // Transform back into joint space
        resultRotation *= worldToJointSpace;

        // Set target rotation to our newly calculated rotation
        joint.targetRotation = resultRotation;
    }
Exemplo n.º 7
0
 /* constructor */
 public MotionGenerator(CharaConfiguration chara, Configuration config, bool debug = false)
 {
     _chara = chara;
     _config = config;
     _debug = debug;
     _root_joint = _chara.root.GetComponent<ConfigurableJoint>();
 }
Exemplo n.º 8
0
	void Start()
	{
		motor = GetComponent<PlayerMotor> ();
        joint = GetComponent<ConfigurableJoint>();
        AC = GetComponent<AnimationController>();

        setJointSetting(jointSpring); 
	}
Exemplo n.º 9
0
    // Use this for initialization
    public override void Start()
    {
        mainCam = Camera.main.transform;
        this.enabled = false;
        hookJoint = gameObject.GetComponent<ConfigurableJoint>();

        rigidbody.solverIterationCount = 60;
    }
Exemplo n.º 10
0
 void Start()
 {
     aJoint = (ConfigurableJoint)gameObject.GetComponent ("ConfigurableJoint");
             aJoint.highAngularXLimit = new SoftJointLimit (){ limit = maxEx, bounciness = 0, damper = dampers, spring = 0 };
             aJoint.lowAngularXLimit = new SoftJointLimit (){ limit = minEx, bounciness = 0, damper = dampers, spring = 0 };
     aJoint.angularXDrive = new JointDrive (){mode = JointDriveMode.Position, positionSpring = 1000, positionDamper = 200, maximumForce = 150};
     goingUp = true;s
             actuateSpeed = 0.10f;
 }
        /// <summary>
        /// Does the PuppetMaster have a muscle for the specified joint.
        /// </summary>
        public bool ContainsJoint(ConfigurableJoint joint)
        {
            if (!CheckIfInitiated()) return false;

            foreach (Muscle m in muscles) {
                if (m.joint == joint) return true;
            }
            return false;
        }
Exemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        if (message == null) {
            enabled = false;
            return;
        }
        message.Register<DoorStateMessage>(ProcessInput);

        joint = GetComponent<ConfigurableJoint>();
    }
	void Start() 
	{
		
		this.configurableJoint = this.gameObject.GetComponent(typeof(ConfigurableJoint)) as ConfigurableJoint;
		this.jointAxisInGlobalCoordinates = transform.TransformDirection(Vector3.Cross(this.configurableJoint.axis, this.configurableJoint.secondaryAxis)).normalized;
		this.initialRotation = this.configurableJoint.transform.localRotation;
		
//		Vector3 objectCenterProjectedOnPlane = MathUtil.ProjectPointOnPlane(jointAxisInGlobalCoordinates, this.configurableJoint.connectedAnchor, transform.position);
		
	}
 static public int get_yMotion(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         pushValue(l, true);
         pushEnum(l, (int)self.yMotion);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int get_linearLimitSpring(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.linearLimitSpring);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int get_configuredInWorldSpace(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.configuredInWorldSpace);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int get_swapBodies(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.swapBodies);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 18
0
	// invocation using a joint and specifying an alpha value
	public static void JointLimit(ConfigurableJoint joint, float scale, float alpha)
	{
		float xMin = joint.lowAngularXLimit.limit;
		float xMax = joint.highAngularXLimit.limit;
		float yMax = joint.angularYLimit.limit;
		float zMax = joint.angularZLimit.limit;
		JointLimit(ref xMin, ref xMax, ref yMax, ref zMax, joint.transform.TransformPoint(joint.anchor), joint.transform.rotation, joint.axis, joint.secondaryAxis, scale, alpha);
		SoftJointLimit limit = joint.lowAngularXLimit; limit.limit = xMin; joint.lowAngularXLimit = limit;
		limit = joint.highAngularXLimit; limit.limit = xMax; joint.highAngularXLimit = limit;
		limit = joint.angularYLimit; limit.limit = yMax; joint.angularYLimit = limit;
		limit = joint.angularZLimit; limit.limit = zMax; joint.angularZLimit = limit;
	}
 static public int get_highAngularXLimit(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.highAngularXLimit);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int get_targetAngularVelocity(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.targetAngularVelocity);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 21
0
    void Start()
    {
        
        objectsToInsert = GameObject.Find(objectsToInsert.name);

        targetContainer = GameObject.Find(targetContainer.name);
        targetJoint = targetContainer.GetComponent<ConfigurableJoint>();

        targetContainer.GetComponent<OnTouchBehavior>().objectHit += InsertGoal_objectHit;

        maxDistance = targetJoint.linearLimit.limit;
        
    }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint o;
         o=new UnityEngine.ConfigurableJoint();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint o;
         o=new UnityEngine.ConfigurableJoint();
         pushValue(l,true);
         pushValue(l,o);
         return 2;
     }
     catch(Exception e) {
         return error(l,e);
     }
 }
Exemplo n.º 24
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint o;
         o = new UnityEngine.ConfigurableJoint();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        /// <summary>
        /// Write the specified value using the writer.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <param name="writer">Writer.</param>
        public override void Write(object value, ISaveGameWriter writer)
        {
            UnityEngine.ConfigurableJoint configurableJoint = (UnityEngine.ConfigurableJoint)value;
            writer.WriteProperty("secondaryAxis", configurableJoint.secondaryAxis);
            writer.WriteProperty("xMotion", configurableJoint.xMotion);
            writer.WriteProperty("yMotion", configurableJoint.yMotion);
            writer.WriteProperty("zMotion", configurableJoint.zMotion);
            writer.WriteProperty("angularXMotion", configurableJoint.angularXMotion);
            writer.WriteProperty("angularYMotion", configurableJoint.angularYMotion);
            writer.WriteProperty("angularZMotion", configurableJoint.angularZMotion);
            writer.WriteProperty("linearLimitSpring", configurableJoint.linearLimitSpring);
            writer.WriteProperty("angularXLimitSpring", configurableJoint.angularXLimitSpring);
            writer.WriteProperty("angularYZLimitSpring", configurableJoint.angularYZLimitSpring);
            writer.WriteProperty("linearLimit", configurableJoint.linearLimit);
            writer.WriteProperty("lowAngularXLimit", configurableJoint.lowAngularXLimit);
            writer.WriteProperty("highAngularXLimit", configurableJoint.highAngularXLimit);
            writer.WriteProperty("angularYLimit", configurableJoint.angularYLimit);
            writer.WriteProperty("angularZLimit", configurableJoint.angularZLimit);
            writer.WriteProperty("targetPosition", configurableJoint.targetPosition);
            writer.WriteProperty("targetVelocity", configurableJoint.targetVelocity);
            writer.WriteProperty("xDrive", configurableJoint.xDrive);
            writer.WriteProperty("yDrive", configurableJoint.yDrive);
            writer.WriteProperty("zDrive", configurableJoint.zDrive);
            writer.WriteProperty("targetRotation", configurableJoint.targetRotation);
            writer.WriteProperty("targetAngularVelocity", configurableJoint.targetAngularVelocity);
            writer.WriteProperty("rotationDriveMode", configurableJoint.rotationDriveMode);
            writer.WriteProperty("angularXDrive", configurableJoint.angularXDrive);
            writer.WriteProperty("angularYZDrive", configurableJoint.angularYZDrive);
            writer.WriteProperty("slerpDrive", configurableJoint.slerpDrive);
            writer.WriteProperty("projectionMode", configurableJoint.projectionMode);
            writer.WriteProperty("projectionDistance", configurableJoint.projectionDistance);
            writer.WriteProperty("projectionAngle", configurableJoint.projectionAngle);
            writer.WriteProperty("configuredInWorldSpace", configurableJoint.configuredInWorldSpace);
            writer.WriteProperty("swapBodies", configurableJoint.swapBodies);
            writer.WriteProperty("connectedBody", configurableJoint.connectedBody);
            writer.WriteProperty("axis", configurableJoint.axis);
            writer.WriteProperty("anchor", configurableJoint.anchor);
            writer.WriteProperty("connectedAnchor", configurableJoint.connectedAnchor);
            writer.WriteProperty("autoConfigureConnectedAnchor", configurableJoint.autoConfigureConnectedAnchor);
            writer.WriteProperty("breakForce", configurableJoint.breakForce);
            writer.WriteProperty("breakTorque", configurableJoint.breakTorque);
            writer.WriteProperty("enableCollision", configurableJoint.enableCollision);
            writer.WriteProperty("enablePreprocessing", configurableJoint.enablePreprocessing);
#if UNITY_2017_1_OR_NEWER
            writer.WriteProperty("massScale", configurableJoint.massScale);
            writer.WriteProperty("connectedMassScale", configurableJoint.connectedMassScale);
#endif
            writer.WriteProperty("tag", configurableJoint.tag);
            writer.WriteProperty("name", configurableJoint.name);
            writer.WriteProperty("hideFlags", configurableJoint.hideFlags);
        }
Exemplo n.º 26
0
 static public int set_targetRotation(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.Quaternion        v;
         checkType(l, 2, out v);
         self.targetRotation = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 27
0
 static public int set_secondaryAxis(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.Vector3           v;
         checkType(l, 2, out v);
         self.secondaryAxis = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 28
0
 static public int set_angularZLimit(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.SoftJointLimit    v;
         checkValueType(l, 2, out v);
         self.angularZLimit = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_projectionAngle(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         float v;
         checkType(l, 2, out v);
         self.projectionAngle = v;
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static public int set_swapBodies(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         bool v;
         checkType(l, 2, out v);
         self.swapBodies = v;
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static public int set_secondaryAxis(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.Vector3           v;
         checkType(l, 2, out v);
         self.secondaryAxis = v;
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static public int set_yMotion(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint       self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.ConfigurableJointMotion v;
         checkEnum(l, 2, out v);
         self.yMotion = v;
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static public int set_angularZLimit(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.SoftJointLimit    v;
         checkValueType(l, 2, out v);
         self.angularZLimit = v;
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static public int set_targetAngularVelocity(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.Vector3           v;
         checkType(l, 2, out v);
         self.targetAngularVelocity = v;
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static public int set_targetRotation(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.Quaternion        v;
         checkType(l, 2, out v);
         self.targetRotation = v;
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 public void RegisterMultiJoint(Part testPart, ConfigurableJoint multiJoint)
 {
     List<ConfigurableJoint> configJointList;
     if (multiJointDict.TryGetValue(testPart, out configJointList))
     {
         configJointList.Add(multiJoint);
     }
     else
     {
         configJointList = new List<ConfigurableJoint>();
         configJointList.Add(multiJoint);
         multiJointDict.Add(testPart, configJointList);
     }
 }
Exemplo n.º 37
0
 static public int set_targetAngularVelocity(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.Vector3           v;
         checkType(l, 2, out v);
         self.targetAngularVelocity = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_slerpDrive(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.JointDrive        v;
         checkValueType(l, 2, out v);
         self.slerpDrive = v;
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Exemplo n.º 39
0
 static public int set_yMotion(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint       self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.ConfigurableJointMotion v;
         checkEnum(l, 2, out v);
         self.yMotion = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 40
0
 static public int set_swapBodies(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         bool v;
         checkType(l, 2, out v);
         self.swapBodies = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 41
0
 static public int set_projectionAngle(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         float v;
         checkType(l, 2, out v);
         self.projectionAngle = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 42
0
 static public int set_slerpDrive(IntPtr l)
 {
     try {
         UnityEngine.ConfigurableJoint self = (UnityEngine.ConfigurableJoint)checkSelf(l);
         UnityEngine.JointDrive        v;
         checkValueType(l, 2, out v);
         self.slerpDrive = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 43
0
        public Strut(Part parent, Part target, Vector3 targetOffset, Transform parentTransform)
        {
            this.parent = parent;
            this.target = target;
            this.targetOffset = targetOffset;
            this.parentTransform = parentTransform;

            if (parent.vessel.parts.Contains(target))
            {
                joint = parent.parent.gameObject.AddComponent<ConfigurableJoint>();
                joint.connectedBody = target.rigidbody;

                joint.anchor = new Vector3(
                    0,
                    0,
                    Vector3.Distance(
                        parentTransform.position,
                        target.transform.TransformPoint(targetOffset)
                    ) / 2
                );
                joint.axis = new Vector3(0, 0, 1);
                joint.xMotion = ConfigurableJointMotion.Locked;
                joint.yMotion = ConfigurableJointMotion.Locked;
                joint.zMotion = ConfigurableJointMotion.Locked;
                joint.angularXMotion = ConfigurableJointMotion.Locked;
                joint.angularYMotion = ConfigurableJointMotion.Locked;
                joint.angularZMotion = ConfigurableJointMotion.Locked;

                LineObj = new GameObject();
                LineObj.name = "quantumstrut";

                lr = LineObj.AddComponent<LineRenderer>();
                lr.useWorldSpace = true;

                Material = QuantumStrut.LaserMaterial;
                StartColor = Color.white;
                EndColor = Color.white;
                StartSize = 0.03f;
                EndSize = 0.0075f;

                lr.SetVertexCount(2);
                lr.SetPosition(0, Vector3.zero);
                lr.SetPosition(1, Vector3.zero);
            }
            else
            {
                Destroy();
            }
        }
 static void ConfigurableJoint_projectionAngle(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.ConfigurableJoint _this = (UnityEngine.ConfigurableJoint)vc.csObj;
         var result = _this.projectionAngle;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single arg0 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.ConfigurableJoint _this = (UnityEngine.ConfigurableJoint)vc.csObj;
         _this.projectionAngle = arg0;
     }
 }
 static void ConfigurableJoint_projectionMode(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.ConfigurableJoint _this = (UnityEngine.ConfigurableJoint)vc.csObj;
         var result = _this.projectionMode;
         JSApi.setEnum((int)JSApi.SetType.Rval, (int)result);
     }
     else
     {
         UnityEngine.JointProjectionMode arg0  = (UnityEngine.JointProjectionMode)JSApi.getEnum((int)JSApi.GetType.Arg);
         UnityEngine.ConfigurableJoint   _this = (UnityEngine.ConfigurableJoint)vc.csObj;
         _this.projectionMode = 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;
     }
 }
// fields

// properties
    static void ConfigurableJoint_secondaryAxis(JSVCall vc)
    {
        if (vc.bGet)
        {
            UnityEngine.ConfigurableJoint _this = (UnityEngine.ConfigurableJoint)vc.csObj;
            var result = _this.secondaryAxis;
            JSApi.setVector3S((int)JSApi.SetType.Rval, result);
        }
        else
        {
            UnityEngine.Vector3           arg0  = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg);
            UnityEngine.ConfigurableJoint _this = (UnityEngine.ConfigurableJoint)vc.csObj;
            _this.secondaryAxis = arg0;
        }
    }
 static void ConfigurableJoint_zMotion(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.ConfigurableJoint _this = (UnityEngine.ConfigurableJoint)vc.csObj;
         var result = _this.zMotion;
         JSApi.setEnum((int)JSApi.SetType.Rval, (int)result);
     }
     else
     {
         UnityEngine.ConfigurableJointMotion arg0  = (UnityEngine.ConfigurableJointMotion)JSApi.getEnum((int)JSApi.GetType.Arg);
         UnityEngine.ConfigurableJoint       _this = (UnityEngine.ConfigurableJoint)vc.csObj;
         _this.zMotion = arg0;
     }
 }
Exemplo n.º 49
0
    // covert local space rotation to joint space
    public static Quaternion LocalToJoint(ConfigurableJoint jnt,
        Quaternion init,
        Quaternion tar)
    {
        Vector3 right = jnt.axis;
        Vector3 forward = Vector3.Cross(jnt.axis, jnt.secondaryAxis).normalized;
        Vector3 up = Vector3.Cross(forward, right).normalized;

        Quaternion w2j = Quaternion.LookRotation(forward, up);

        Quaternion res = Quaternion.Inverse(w2j);
        res *= Quaternion.Inverse(tar) * init;
        res *= w2j;
        return res;
    }
 static void ConfigurableJoint_swapBodies(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.ConfigurableJoint _this = (UnityEngine.ConfigurableJoint)vc.csObj;
         var result = _this.swapBodies;
         JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(result));
     }
     else
     {
         System.Boolean arg0 = (System.Boolean)JSApi.getBooleanS((int)JSApi.GetType.Arg);
         UnityEngine.ConfigurableJoint _this = (UnityEngine.ConfigurableJoint)vc.csObj;
         _this.swapBodies = arg0;
     }
 }
Exemplo n.º 51
0
    void Configure(ConfigurableJoint cj)
    {
        //cj.autoConfigureConnectedAnchor = false;
        //cj.connectedAnchor = Vector3.zero;
        //cj.anchor = Vector3.zero;

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

        cj.projectionMode = JointProjectionMode.PositionAndRotation;
        //cj.enableCollision = true;
        /*if(Random.Range(0,100) < 20){
            cj.breakForce = 500 + Random.Range(0,200);
        }*/
    }
    public override void Grab(Transform grabAnchor, Rigidbody rb)
    {
        transform.parent = grabAnchor;
        //transform.localPosition = Vector3.zero;

        confJoint = gameObject.AddComponent<ConfigurableJoint>();
        confJoint.connectedBody = rb;
        confJoint.xMotion = ConfigurableJointMotion.Locked;
        confJoint.yMotion = ConfigurableJointMotion.Locked;
        confJoint.zMotion = ConfigurableJointMotion.Locked;

        /*
        JointDrive xDrive = new JointDrive();
        xDrive.mode = JointDriveMode.Position;
        confJoint.angularXDrive = xDrive;
        JointDrive YZDrive = new JointDrive();
        YZDrive.mode = JointDriveMode.Position;
        confJoint.angularYZDrive = YZDrive;
        */

        /*
        hingeJoint = gameObject.AddComponent<HingeJoint>();
        hingeJoint.connectedBody = rb;
        hingeJoint.connectedAnchor = Vector3.zero;
        //hingeJoint.anchor = grabAnchor.position;
        JointSpring tempSpring = new JointSpring();
        tempSpring.spring = 10;
        tempSpring.damper = 1;
        hingeJoint.spring = tempSpring;
        */
        /*
        springJoint = gameObject.AddComponent<SpringJoint>();
        springJoint.connectedBody = rb;
        springJoint.connectedAnchor = Vector3.zero;
        springJoint.anchor = grabAnchor.position;
        springJoint.minDistance = 0.5f;
        springJoint.maxDistance = 0.5f;
        springJoint.spring = 10;
        springJoint.damper = 1;
        */
    }
Exemplo n.º 53
0
	void Start () {
		berry = GameObject.Find("berry conf joint");

		chain = new GameObject[100];
		maxDiffC = chainLength * maxChainCount;
		jointWeb = web.GetComponent<ConfigurableJoint> ();
		if (pointB != null) {
			diff = pointB.transform.position + pointBAchor - web.transform.position;
			float pointBDiffC = Mathf.Sqrt(diff.x * diff.x + diff.y * diff.y);
			diffX = maxDiffC / pointBDiffC * diff.x / maxChainCount;
			diffY = maxDiffC / pointBDiffC * diff.y / maxChainCount;
			webState = "creatingWeb";
			while (webState == "creatingWeb") {
				createWeb(pointB.transform.position, pointBAchor, true);

				int i = chainCount;
				//chain[i].rigidbody.fixedAngle = true;
				if (pointB.GetComponent<Collider2D>().OverlapPoint(chain[1].transform.position + new Vector3(diffX, diffY, 0))) {

					chainCount = i;
					ConfigurableJoint jointChain = chain[1].GetComponent<ConfigurableJoint> ();
					jointChain.connectedBody = pointB.GetComponent<Rigidbody>();
					jointChain.connectedAnchor = pointBAchor;
					//jointChain.enabled = true;	
					for (int y = 1; y <= chainCount; y ++){
						chain[y].GetComponent<Rigidbody>().drag = drag;
						//chain[y].rigidbody.angularDrag = 2;
						//chain[y].rigidbody.centerOfMass = new Vector2(0, -0.3F);
					}

					//i = maxChainCount / 2;
					webState = "enableWeb";

				}
			}
		}
	}
	/*
	 * Initialize
	 * */
	void OnEnable()
	{
		joint = (ConfigurableJoint) target;
	}
Exemplo n.º 55
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;
        }
Exemplo n.º 56
0
 void SetBreakPrc(ConfigurableJoint joint, float prc)
 {
     if(Random.Range(0,100) < prc){
         joint.breakForce = toughess - 300 + Random.Range(0,200);
     }
     else{
         joint.breakForce = toughess;
     }
 }
Exemplo n.º 57
0
	/*
	 * Creates a joint limit handle
	 * */
	// basic invocation using a joint
	public static void JointLimit(ConfigurableJoint joint, float scale)
	{
		JointLimit(joint, scale, 1f);
	}
Exemplo n.º 58
0
        private void InitKnob()
        {
            rb = GetComponent<Rigidbody>();
            if (rb == null)
            {
                rb = gameObject.AddComponent<Rigidbody>();
                rb.angularDrag = 10; // otherwise knob will continue to move too far on its own
            }
            rb.isKinematic = false;
            rb.useGravity = false;

            io = GetComponent<VRTK_InteractableObject>();
            if (io == null)
            {
                io = gameObject.AddComponent<VRTK_InteractableObject>();
            }
            io.isGrabbable = true;
            io.precisionSnap = true;
            io.stayGrabbedOnTeleport = false;
            io.grabAttachMechanic = VRTK_InteractableObject.GrabAttachType.Track_Object;

            cj = GetComponent<ConfigurableJoint>();
            if (cj == null)
            {
                cj = gameObject.AddComponent<ConfigurableJoint>();
                cj.configuredInWorldSpace = false;
                cjCreated = true;
            }

            if (connectedTo)
            {
                Rigidbody rb2 = connectedTo.GetComponent<Rigidbody>();
                if (rb2 == null)
                {
                    rb2 = connectedTo.AddComponent<Rigidbody>();
                    rb2.useGravity = false;
                    rb2.isKinematic = true;
                }
            }
        }
        /// <summary>
        /// Returns the index of the muscle that has the specified Joint. Returns -1 if not found.
        /// </summary>
        public int GetMuscleIndex(ConfigurableJoint joint)
        {
            if (!CheckIfInitiated()) return -1;

            if (joint == null) {
                Debug.LogWarning("Joint is null, can not get muscle index.", transform);
                return -1;
            }

            for (int i = 0; i < muscles.Length; i++) {
                if (muscles[i].joint == joint) return i;
            }

            Debug.LogWarning("No muscle with Joint " + joint.name + "found on the PuppetMaster.", transform);
            return -1;
        }
 /// <summary>
 /// Returns the muscle of the specified Joint.
 /// </summary>
 public Muscle GetMuscle(ConfigurableJoint joint)
 {
     int index = GetMuscleIndex(joint);
     if (index == -1) return null;
     return muscles[index];
 }