public static string ToJson(TargetJoint2D data) { return(JsonUtility.ToJson(data)); }
// Start is called before the first frame update void Start() { target = GetComponent <TargetJoint2D>(); boxCollider = GetComponent <BoxCollider2D>(); }
private void Start() { tj = GetComponent <TargetJoint2D>(); tj.enabled = false; }
// grab the given object void Grabbed(GameObject grabbable, bool gStatic = false) { grabbed = true; grabbedGO = grabbable; grabbedStatic = gStatic; ApplySoap ap = grabbedGO.GetComponent <ApplySoap>(); if (ap != null) { ap.grabbed = true; } // handRB.gameObject.SetActive(true); if (!grabbedStatic) { previousParent = grabbedGO.transform.parent; storedLocal = handRB.transform.localPosition; storedLayer = grabbable.layer; storedLayerName = LayerMask.LayerToName(grabbable.layer); // Debug.Log(storedLayerName); //handRB.transform.position = grabbedGO.transform.position; grabbable.layer = LayerMask.NameToLayer("Ignore Player"); grabbedGO.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); Joint2D[] connectedJoints = grabbedGO.GetComponentsInChildren <Joint2D>(); foreach (Joint2D joint in connectedJoints) { connectedBodies.Add(joint.connectedBody); if (grabbedGO.tag != "GrabbableKeepRotation") { joint.connectedBody.gameObject.layer = LayerMask.NameToLayer("Ignore Player"); } } //Debug.Log("grabbed"); if (grabbedGO.tag != "GrabbableKeepRotation") { rj = grabbedGO.AddComponent <RelativeJoint2D>(); rj.connectedBody = handRB; autoCorrectNextFrame = true; angleOffset = -Extensions.Angle(-transform.up) - grabbedGO.transform.eulerAngles.z; rj.correctionScale = 0.7f; grabbedGO.GetComponent <Rigidbody2D>().freezeRotation = true; } else { TargetJoint2D joint1 = grabbedGO.AddComponent <TargetJoint2D>(); TargetJoint2D joint2 = handRB.gameObject.AddComponent <TargetJoint2D>(); dtj = new DoubleTargetJoint(joint1, joint2, handRB.transform.position); stillRotates = true; //TargetJoint2D tj = gr } changeInAngleTime = Time.time; previouseAngle = grabbedGO.transform.eulerAngles.z; ActivateableObject ao = grabbedGO.GetComponent <ActivateableObject>(); // rj.breakForce = 6000; } else { mover.GrabbedStatic(grabbedGO); } if (left) { handLimiter.leftGrabbed = grabbedGO.transform; } else { handLimiter.rightGrabbed = grabbedGO.transform; } hand.grabbing = true; previouseAngle = grabbedGO.transform.eulerAngles.z; PointGiver pg = grabbedGO.GetComponent <PointGiver>(); if (pg != null) { pg.Caught(); } }
// Start is called before the first frame update void Start() { targetJoint = GetComponent <TargetJoint2D>(); spawnPosition = transform.position; }
// Start is called before the first frame update void Start() { orginalPosition = gameObject.transform.position; boxCollider = GetComponent <BoxCollider2D>(); target = GetComponent <TargetJoint2D>(); }
private void Awake() { targetJoint = GetComponent <TargetJoint2D>(); }
private void Start() { anchorJoint = GetComponent <SpringJoint2D>(); rb = GetComponent <Rigidbody2D>(); mouseJoint = GetComponent <TargetJoint2D>(); }
// Start is called before the first frame update void Start() { Joint = gameObject.GetComponent <TargetJoint2D>(); Target1 = transform.position; Joint.target = Target1; }
// public void ApplyAnchors(Joint2D joint) { // if (jointType == JointType2D.RelativeJoint2D) // return; // if (jointType == JointType2D.TargetJoint2D) { // ((TargetJoint2D) joint).anchor = anchor; // ((TargetJoint2D) joint).target = target; // needs to be world relative // return; // } // ((AnchoredJoint2D) joint).anchor = anchor; // ((AnchoredJoint2D) joint).connectedAnchor = connectedAnchor; // } // public void ApplyLimits(Joint2D joint, GameObject go, Rigidbody2D connectedBody) { // if (jointType != JointType2D.HingeJoint2D) // return; // Quaternion startRotation = go.transform.rotation; // if (useLimits && limits.relativeTo == AngleLimitsRelativeTo.ZeroRotation && connectedBody) { // go.transform.rotation = connectedBody.transform.rotation; // // setting the connectedBody triggers a re-calculation of the reference angle // joint.connectedBody = connectedBody; // } // ((HingeJoint2D) joint).limits = limits.ToJointAngleLimits2D(); // if (useLimits && limits.relativeTo == AngleLimitsRelativeTo.ZeroRotation && connectedBody) // go.transform.rotation = startRotation; // } public Joint2D CreateOrApply(GameObject go, Rigidbody2D connectedBody, Joint2D joint = null) { if (joint && !JointMatchesJointType(joint)) { GameObject.Destroy(joint); joint = null; } if (jointType == JointType2D.DistanceJoint2D) { DistanceJoint2D distanceJoint = (DistanceJoint2D)joint ?? go.AddComponent <DistanceJoint2D>(); ConfigureAnchoredJoint(distanceJoint, connectedBody); distanceJoint.maxDistanceOnly = maxDistanceOnly; distanceJoint.autoConfigureDistance = autoConfigureDistance; if (!autoConfigureDistance) { distanceJoint.distance = distance; } joint = distanceJoint; } if (jointType == JointType2D.FixedJoint2D) { FixedJoint2D fixedJoint = (FixedJoint2D)joint ?? go.AddComponent <FixedJoint2D>(); ConfigureAnchoredJoint(fixedJoint, connectedBody); fixedJoint.frequency = frequency; fixedJoint.dampingRatio = dampingRatio; joint = fixedJoint; } if (jointType == JointType2D.FrictionJoint2D) { FrictionJoint2D frictionJoint = (FrictionJoint2D)joint ?? go.AddComponent <FrictionJoint2D>(); ConfigureAnchoredJoint(frictionJoint, connectedBody); frictionJoint.maxForce = maxFrictionForce; frictionJoint.maxTorque = maxFrictionTorque; joint = frictionJoint; } if (jointType == JointType2D.HingeJoint2D) { Quaternion startRotation = go.transform.rotation; // if (useLimits && limits.relativeTo == AngleLimitsRelativeTo.ZeroRotation && connectedBody) // go.transform.rotation = connectedBody.transform.rotation; HingeJoint2D hingeJoint = (HingeJoint2D)joint ?? go.AddComponent <HingeJoint2D>(); ConfigureAnchoredJoint(hingeJoint, connectedBody); hingeJoint.limits = limits.ToJointAngleLimits2D(); hingeJoint.useLimits = useLimits; JointMotor2D m = new JointMotor2D(); m.maxMotorTorque = motor.maxMotorTorque; m.motorSpeed = motor.motorSpeed; hingeJoint.motor = m; hingeJoint.useMotor = useMotor; joint = hingeJoint; // if (useLimits && limits.relativeTo == AngleLimitsRelativeTo.ZeroRotation && connectedBody) // go.transform.rotation = startRotation; } if (jointType == JointType2D.RelativeJoint2D) { RelativeJoint2D relativeJoint = (RelativeJoint2D)joint ?? go.AddComponent <RelativeJoint2D>(); ConfigureJoint(relativeJoint, connectedBody); relativeJoint.autoConfigureOffset = autoConfigureOffset; if (!autoConfigureOffset) { relativeJoint.linearOffset = linearOffset; relativeJoint.angularOffset = angularOffset; } relativeJoint.correctionScale = correctionScale; relativeJoint.maxForce = maxForce; relativeJoint.maxTorque = maxTorque; joint = relativeJoint; } if (jointType == JointType2D.SliderJoint2D) { SliderJoint2D sliderJoint = (SliderJoint2D)joint ?? go.AddComponent <SliderJoint2D>(); ConfigureAnchoredJoint(sliderJoint, connectedBody); joint = sliderJoint; } if (jointType == JointType2D.SpringJoint2D) { SpringJoint2D springJoint = (SpringJoint2D)joint ?? go.AddComponent <SpringJoint2D>(); ConfigureAnchoredJoint(springJoint, connectedBody); springJoint.autoConfigureDistance = autoConfigureDistance; if (!autoConfigureDistance) { springJoint.distance = distance; } springJoint.dampingRatio = dampingRatio; springJoint.frequency = frequency; joint = springJoint; } if (jointType == JointType2D.TargetJoint2D) { TargetJoint2D targetJoint = (TargetJoint2D)joint ?? go.AddComponent <TargetJoint2D>(); targetJoint.autoConfigureTarget = false; targetJoint.anchor = anchor; targetJoint.target = target; targetJoint.maxForce = maxForce; targetJoint.dampingRatio = dampingRatio; targetJoint.frequency = frequency; joint = targetJoint; } if (jointType == JointType2D.WheelJoint2D) { WheelJoint2D wheelJoint = (WheelJoint2D)joint ?? go.AddComponent <WheelJoint2D>(); ConfigureJoint(wheelJoint, connectedBody); joint = wheelJoint; } return(joint); }
// Start is called before the first frame update void Start() { targetJoint = GetComponent <TargetJoint2D>(); }
public void Clean() { Destroy(targetJoint); targetJoint = null; }
private void Awake() { joint = this.gameObject.GetComponent <TargetJoint2D>(); joint.enabled = false; }
override protected void Initialise() { base.Initialise(); distJoints = GetComponents <DistanceJoint2D>(); targetJoint = GetComponent <TargetJoint2D>(); }
public void Awake() { m_hinge = GetComponent <HingeJoint2D>(); m_target = GetComponent <TargetJoint2D>(); }