//plaes and configures neck's hinge joints void HingeJointSetupN() { HingeJoint2D thisAnchor = GameObject.Find("llamaHead").gameObject.AddComponent <HingeJoint2D> (); thisAnchor.connectedBody = GameObject.Find("neck base").GetComponent <Rigidbody2D> (); Vector2 neckAnchor = new Vector2(0f, -0.27f); thisAnchor.anchor = neckAnchor; Vector2 neckConnect = new Vector2(0.004f, -0.27f); thisAnchor.connectedAnchor = neckConnect; }
// Use this for initialization void Start() { // Let's ask the Unity Engine to search for all Game Objects that are tagged "Propeller" // and to return us the 'first' one it finds. This is safe for us to do in this example // as we only have one Game Object tagged "Propeller". GameObject propellerGO = GameObject.FindGameObjectWithTag("Propeller"); // Now let's get the HingeJoint2D component spinningHingeJoint = propellerGO.GetComponent <HingeJoint2D>(); // Okay, we're ready to go }
// Use this for initialization void Start() { LeftUpPoint = GameObject.Find("LeftUpPoint"); RightDownPoint = GameObject.Find("RightDownPoint"); shovel = GameObject.Find("Shovel"); joint = shovel.GetComponent <HingeJoint2D>(); rigidbody = shovel.GetComponent <Rigidbody2D>(); var leftWall = GameObject.Find("LeftWall").GetComponent <Renderer>().enabled = false; var rightWall = GameObject.Find("RightWall").GetComponent <Renderer>().enabled = false; var ground = GameObject.Find("Ground").GetComponent <Renderer>().enabled = false; }
IEnumerator EjectCansat() { CanSatJoint = CanSat.GetComponent <FixedJoint2D>(); NoseCornJoint = NoseCorn.GetComponent <FixedJoint2D>(); yield return(new WaitForSeconds(0.3f)); //CanSat.GetComponent<BoxCollider2D>().enabled = true; //CanSat.GetComponent<BoxCollider2D>().isTrigger = false; CanSat.GetComponent <BoxCollider2D>().isTrigger = false; NoseCornJoint.enabled = false; NoseCorn.GetComponent <Rigidbody2D>().AddForce(new Vector2(0.0f, 0.01f), ForceMode2D.Impulse); NoseCorn.GetComponent <Rigidbody2D>().AddTorque(0.001f, ForceMode2D.Impulse); yield return(new WaitForSeconds(0.3f)); GetComponent <AudioSource>().PlayOneShot(CansatSound); CanSatJoint.enabled = false; CanSat.GetComponent <Rigidbody2D>().AddForce(new Vector2(0, 0.1f), ForceMode2D.Impulse); ScoreBody = CanSat.GetComponent <Rigidbody2D>(); SideThrustJet.transform.parent = ScoreBody.transform; SideThrustJetL.transform.parent = ScoreBody.transform; SideTrustR = Vector2.right * -2.0f; SideTrustL = Vector2.right * 2.0f; SideThrustJet.transform.localPosition = SideTrustR; SideThrustJet.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); SideThrustJetL.transform.localPosition = SideTrustL; SideThrustJetL.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); MainCamera.GetComponent <FollowCamera>().objTarget = CanSat; MapCamera.GetComponent <FollowCamera>().objTarget = CanSat; ParaPrefab = (GameObject)Resources.Load("Prefabs/Para"); GameObject ParaObject = (GameObject)Instantiate(ParaPrefab); ParaObject.name = "Para"; ParaObject.transform.position = CanSat.transform.position; yield return(new WaitForSeconds(0.3f)); ParaJoint = ParaObject.GetComponent <HingeJoint2D>(); ParaJoint.connectedBody = CanSat.GetComponent <Rigidbody2D>(); ParaJoint.anchor = new Vector2(0.0f, -4.5f); ParaJoint.connectedAnchor = new Vector2(0.0f, 4.0f); yield return(null); }
void Start() { berry = GameObject.Find("berry"); chain = new GameObject[100]; maxDiffC = chainLength * maxChainCount; jointWeb = web.GetComponent <HingeJoint2D> (); if (pointB != null) { if (pointB.name == "berry") { webStateCollisionBerry = true; } if (pointB.name == "spider") { gSpiderClass.websSpider.Add(gameObject.GetInstanceID()); } 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].rigidbody2D.fixedAngle = true; if (pointB.GetComponent <Collider2D>().OverlapPoint(chain[1].transform.position + new Vector3(diffX, diffY, 0)) || pointB.GetComponent <Collider2D>().OverlapPoint(chain[1].transform.position + new Vector3(diffX / 2, diffY / 2, 0))) { chainCount = i; HingeJoint2D jointChain = chain[1].GetComponent <HingeJoint2D> (); jointChain.connectedBody = pointB.GetComponent <Rigidbody2D>(); jointChain.connectedAnchor = pointBAchor * 1024; jointChain.enabled = true; jointChain.useLimits = false; for (int y = 1; y <= chainCount; y++) { chain[y].GetComponent <Rigidbody2D>().drag = drag; chain[y].GetComponent <BoxCollider2D>().enabled = true; //chain[y].rigidbody2D.angularDrag = 2; //chain[y].rigidbody2D.centerOfMass = new Vector2(0, -0.3F); } //i = maxChainCount / 2; webState = "enableWeb"; } } } fixedCounter = 0; }
public void DropObject() { if (heldObject || rotatingHeldObject) { heldObjectRB.drag = originalHeldObjectDrag; heldHingeJoint.connectedBody = null; heldHingeJoint.enabled = false; heldHingeJoint = null; heldObjectRB = null; heldObject = null; rotatingHeldObject = false; } }
public mySingleJoint(GameObject bd, Vector2 pos) { pref = (GameObject)Resources.Load("Prefs/TJoint", typeof(GameObject)); GameObject temp = GameObject.Instantiate(pref); temp.AddComponent <JointCtrl>(); temp.GetComponent <JointCtrl>().myJoint = this; JObj = GameObject.Find("Main Camera").GetComponent <camera>().GetBody(); temp.transform.position = JObj.transform.TransformPoint(pos); comp = JObj.AddComponent <HingeJoint2D>(); comp.anchor = pos; }
private Vector2 _lightScale; // Flicker and change colour will be centered around the initial scale private void Start() { _lanternHinge = GetComponent <HingeJoint2D>(); _lanternBody = GetComponent <Rigidbody2D>(); _lanternCollider = GetComponent <PolygonCollider2D>(); GetChildComponents(); _lanternCollider.enabled = false; _lightScale = _light.transform.localScale; SetColour(); StartCoroutine("Flicker"); }
void GenerateRope() { Rigidbody2D previousRB = _Hook; for (int i = 0; i < _NumberOfLinks; i++) { GameObject link = Instantiate(_LinkPrefab, transform); HingeJoint2D joint = link.GetComponent <HingeJoint2D>(); joint.connectedBody = previousRB; previousRB = link.GetComponent <Rigidbody2D>(); } }
void Start() { hJoint = gameObject.GetComponent <HingeJoint2D>(); rigidBody = gameObject.GetComponent <Rigidbody2D>(); lineRenderer = gameObject.GetComponent <LineRenderer>(); spriteRenderer = gameObject.GetComponent <SpriteRenderer>(); sticked = false; lastBestPositionJoint = 0; lastBestPositionSelected = 0; ancors.transform.GetChild(lastBestPositionSelected).gameObject.GetComponent <JointBehaviour>().selected(); won = false; touches = 0; }
void Connect_Neck() { HingeJoint2D thisAnchor = GameObject.FindWithTag("New Neck").gameObject.AddComponent <HingeJoint2D> (); thisAnchor.connectedBody = GameObject.FindWithTag("Current Neck").GetComponent <Rigidbody2D> (); Vector2 neckAnchor = new Vector2(0f, -0.27f); thisAnchor.anchor = neckAnchor; thisAnchor.autoConfigureConnectedAnchor = false; Vector2 neckConnect = new Vector2(0.004f, 0.27f); thisAnchor.connectedAnchor = neckConnect; }
private void GenetateRope() { Rigidbody2D previousRB = hook; for (int i = 0; i < chainNumber; i++) { GameObject chain = Instantiate(chainPrefab, transform); hingeJoint = chain.GetComponent <HingeJoint2D>(); hingeJoint.connectedBody = previousRB; previousRB = chain.GetComponent <Rigidbody2D>(); } }
// Use this for initialization void Start() { anim = GetComponentInChildren <Animator> (); if (anim == null) { Debug.Log("Couldn't get Animator from child"); } joint = GetComponentInParent <HingeJoint2D> (); if (joint == null) { Debug.Log("Couldn't load SpringJoint2D"); } }
void GrabThing(Rigidbody2D rigidbody2D) { if (GrabJoint != null) { return; } GrabJoint = this.gameObject.AddComponent <HingeJoint2D>(); GrabJoint.connectedBody = rigidbody2D; GrabJoint.anchor = new Vector2(0, 4.68f); massBuffer = centerController.getRig().mass; centerController.getRig().mass = 1; centerController.gameObject.transform.SetParent(rigidbody2D.gameObject.transform); }
private void OnMouseDown() { GameManager.Instance.SetLockCamera(true); Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0); Vector3 objPosition = Camera.main.ScreenToWorldPoint(mousePosition); offset = objPosition - transform.position; jointObj = Instantiate(dragPrefab, objPosition, transform.rotation) as GameObject; hj2d = jointObj.GetComponent <HingeJoint2D>(); hj2d.connectedAnchor = transform.InverseTransformPoint(mousePosition); hj2d.connectedBody = rb2d; }
private void ConnectAnchor2() { Anchor2.transform.position = Links[Links.Length - 1].position + Anchor2Offset; Rigidbody2D rb = Anchor1.GetComponent <Rigidbody2D>(); Transform lastLink = Links[Links.Length - 1]; HingeJoint2D hj = lastLink.gameObject.AddComponent <HingeJoint2D>(); hj.anchor = lastLink.InverseTransformPoint(lastLink.position - transform.up * YSize * 0.5f); if (rb) { hj.connectedBody = rb; } }
void Awake() { rb = GetComponent <Rigidbody2D>(); joint = GetComponent <HingeJoint2D>(); boxColliders = GetComponents <BoxCollider2D>(); meshRender = GetComponentInChildren <MeshRenderer>(); boxLength = boxColliders[0].size.x; leafList = new List <Leaf>(); FindObjectOfType <Wind>().AddRb(rb); limbRender.GetComponent <MeshRenderer>().sortingLayerName = "Tree"; limbRender.GetComponent <MeshRenderer>().sortingOrder = 0; SetVisible(false); }
// Use this for initialization void Start() { // anchor = new Vector3(-.5f, 0, 0); scaleOffset = GetComponent <TransformOffset>(); joint = GetComponent <HingeJoint2D>(); if (currentSegment < maxSegments) { nextSegment = Instantiate(this.gameObject, transform.position + new Vector3(transform.localScale.x, 0, 0), Quaternion.identity); //nextSegment = Instantiate(this.gameObject, transform.localPosition + new Vector3(.03f, 0, 0), Quaternion.identity); currentSegment += 1; nextSegment.GetComponent <HingeJoint2D>().connectedBody = this.GetComponent <Rigidbody2D>(); } }
public override void OnInspectorGUI() { HingeJoint2D joint = (HingeJoint2D)target; EditMode.DoEditModeInspectorModeButton( EditMode.SceneViewEditMode.JointAngularLimits, "Edit Joint Angular Limits", Styles.editAngularLimitsButton, this ); base.OnInspectorGUI(); }
// Use this for initialization void Start() { _hinge = gameObject.GetComponent <HingeJoint2D>(); if (_hinge == null) { enabled = false; } else { AnchorX = _hinge.connectedAnchor.x; AnchorY = _hinge.connectedAnchor.y; } }
// Update is called once per frame void Update() { timer += Time.deltaTime; if (timer > 3.0f) { HingeJoint2D hinge = GetComponent <HingeJoint2D>(); JointMotor2D motor = hinge.motor; motor.motorSpeed = Random.Range(0, 500); hinge.motor = motor; timer = Random.Range(1, 2); } }
protected virtual void Start() { _transform = transform; _joint = gameObject.AddComponent <HingeJoint2D>(); _joint.enabled = false; _joint.useLimits = false; _joint.useMotor = false; _joint.autoConfigureConnectedAnchor = false; _joint.enableCollision = true; _joint.anchor = anchor; _trigger = (GetComponentInChildren <GymanGrabRgn>()).gameObject; }
void SetupHingeJointComponent(GameObject obj) { HingeJoint2D hj = gameObject.AddComponent <HingeJoint2D>() as HingeJoint2D; hj.connectedBody = obj.GetComponent <Rigidbody2D>(); hj.useLimits = true; JointAngleLimits2D limits = new JointAngleLimits2D(); limits.min = 180f - JointAngleDelta; limits.max = 180f + JointAngleDelta; hj.limits = limits; }
public void Go() { HingeJoint2D[] joints = GetComponentsInChildren <HingeJoint2D>(); for (int i = 0; i < joints.Length; i++) { GameObject parentRef = joints[i].gameObject; Destroy(joints[i]); HingeJoint2D copy = parentRef.AddComponent <HingeJoint2D>(); HingeDeepCopy(copy, joints[i]); } }
void CreateChain() { for (int i = 1; i <= chainLinks; i++) { GameObject zelda = Instantiate(chainLinkPrefab, transform); // Link is too mainstream =P zelda.transform.localPosition = chainLink[i - 1].transform.localPosition + (Vector3.down * linkDistance); zelda.name = "ChainLink" + i.ToString(); HingeJoint2D triforce = zelda.GetComponent <HingeJoint2D>(); // Let's steal the Triforce of wisdom for this to work! triforce.connectedBody = chainLink[i - 1]; // Connect the triforce to previous hero of time triforce.autoConfigureConnectedAnchor = false; triforce.connectedAnchor = Vector2.down * linkDistance; chainLink [i] = triforce.GetComponent <Rigidbody2D> (); } }
public void removeLink() { /* if (top.gameObject.GetComponent<RopeSegment>().isPlayerAttached) * { * player.Slide(-1); * }*/ HingeJoint2D newTop = top.gameObject.GetComponent <RopeSegment>().connectedBelow.GetComponent <HingeJoint2D>(); newTop.connectedBody = hook; newTop.gameObject.transform.position = hook.gameObject.transform.position; newTop.GetComponent <RopeSegment>().ResetAnchor(); Destroy(top.gameObject); top = newTop; }
private void StartChilds() { int count = transform.childCount; childTrans = new Transform[count]; for (int i = 0; i < count; i++) { childTrans[i] = transform.GetChild(i).transform; } int lenght = childTrans.Length - 1; line.positionCount = lenght; lastNodeJoint = childTrans[lenght].GetComponent <HingeJoint2D>(); }
private void releaseRigidBody(Rigidbody2D rb) { rb.fixedAngle = false; rb.gameObject.AddComponent <PartDestroyer>(); HingeJoint2D hingeJoint = rb.GetComponent <HingeJoint2D>(); if (hingeJoint) { GameObject.Destroy(hingeJoint); } rb.transform.parent = null; }
void Start() { IsWalk = false; IsAtk = false; HJ2D = GameObject.Find("DownBody").GetComponent <HingeJoint2D>(); player = GameObject.Find("Player").GetComponent <Transform>(); SpriteOriginalScale = enemyOBG.transform.localScale; this.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation; minVelocity = -1f; maxVelocity = 1f; }
void GenerateRope() { //Generates rope by randomly selecting from an array of link prefabs Rigidbody2D previousRB = hook; for (int i = 0; i < links; i++) { int a = Random.Range(0, linkPrefab.Length - 1); GameObject link = Instantiate(linkPrefab[a], transform); HingeJoint2D joint = link.GetComponent <HingeJoint2D>(); joint.connectedBody = previousRB; previousRB = link.GetComponent <Rigidbody2D>(); } }