public void GrabPiece() { if (_attachedPiece != null) { RelativeJoint2D attachedJoint = _attachedPiece.GetComponent <RelativeJoint2D>(); if (_attachedJoint == attachedJoint) { _attachedPiece.Unattach(); Destroy(_attachedJoint); } _attachedPiece = null; _attachedJoint = null; } if (_pieceSelector.CurrentPiece != null && !(_pieceSelector.CurrentPiece is BasePiece)) { _attachedPiece = _pieceSelector.CurrentPiece; _attachedPiece.Unattach(); _attachedPiece.gameObject.layer = _pieceLayer; _pieceSelector.transform.position = _attachedPiece.transform.position; _attachedJoint = _attachedPiece.gameObject.AddComponent <RelativeJoint2D>(); _attachedJoint.connectedBody = _pieceSelector.GetComponent <Rigidbody2D>(); _attachedJoint.autoConfigureOffset = false; _attachedJoint.correctionScale = 0.1f; _attachedJoint.linearOffset = Vector2.zero; _attachedJoint.breakForce = 500.0f * _attachedPiece.GetComponent <Rigidbody2D>()?.mass ?? 1.0f; } }
void OnCollisionEnter2D(Collision2D col) { // Don't do anything if hand already has a star or the mouse is holding the hand down if (hasStar || !gameController.armLoose) { return; } // Grab the star upon collision if (col.gameObject.tag == "Star") { RelativeJoint2D newRelativeJoint = gameObject.AddComponent <RelativeJoint2D>(); DistanceJoint2D newDistanceJoint2D = gameObject.AddComponent <DistanceJoint2D>(); newDistanceJoint2D.distance = 0f; // newDistanceJoint2D.maxDistanceOnly = true; newRelativeJoint.connectedBody = col.rigidbody; newDistanceJoint2D.connectedBody = col.rigidbody; col.rigidbody.constraints = RigidbodyConstraints2D.FreezeRotation; hasStar = true; col.transform.parent = transform.parent; gameController.StarGrabbed(col.gameObject); col.gameObject.GetComponent <Star>().HasBeenGrabbed(); col.rigidbody.velocity = Vector2.zero; GetComponent <AudioSource>().Play(); col.transform.position = transform.position; } }
public override void AttachToRB(Rigidbody2D attachedTo, PlayerController pc) { if (!isAttached) { Piece p = attachedTo.GetComponent <Piece>(); if (p == null) { p = attachedTo.GetComponentInParent <Piece>(); } if (p != null) { RelativeJoint2D fj2d = gameObject.AddComponent <RelativeJoint2D>(); fj2d.connectedBody = attachedTo; fj2d.breakForce = breakForce; fj2d.correctionScale = 0.25f; activeJoints.Add(fj2d); current_pc = pc; isAttached = true; p.piecesAttachedToMe.Add(this); parentPiece = p; if (current_pc != null) { current_pc.AddPower(power); } } } }
public void OnSceneGUI() { RelativeJoint2D relativeJoint2D = (RelativeJoint2D)this.target; if (!relativeJoint2D.enabled) { return; } Vector3 vector = relativeJoint2D.target; Vector3 vector2 = (!relativeJoint2D.connectedBody) ? Vector3.zero : relativeJoint2D.connectedBody.transform.position; Handles.color = Color.green; Joint2DEditor.DrawAALine(vector, vector2); float d = HandleUtility.GetHandleSize(vector2) * 0.16f; Vector3 b = Vector3.left * d; Vector3 b2 = Vector3.up * d; Joint2DEditor.DrawAALine(vector2 - b, vector2 + b); Joint2DEditor.DrawAALine(vector2 - b2, vector2 + b2); float d2 = HandleUtility.GetHandleSize(vector) * 0.16f; Vector3 b3 = Vector3.left * d2; Vector3 b4 = Vector3.up * d2; Joint2DEditor.DrawAALine(vector - b3, vector + b3); Joint2DEditor.DrawAALine(vector - b4, vector + b4); }
public void OnSceneGUI() { RelativeJoint2D target1 = (RelativeJoint2D)this.target; if (!target1.enabled) { return; } Vector3 target2 = (Vector3)target1.target; Vector3 vector3_1 = !(bool)((Object)target1.connectedBody) ? Vector3.zero : target1.connectedBody.transform.position; Handles.color = Color.green; Joint2DEditor.DrawAALine(target2, vector3_1); float num1 = HandleUtility.GetHandleSize(vector3_1) * 0.16f; Vector3 vector3_2 = Vector3.left * num1; Vector3 vector3_3 = Vector3.up * num1; Joint2DEditor.DrawAALine(vector3_1 - vector3_2, vector3_1 + vector3_2); Joint2DEditor.DrawAALine(vector3_1 - vector3_3, vector3_1 + vector3_3); float num2 = HandleUtility.GetHandleSize(target2) * 0.16f; Vector3 vector3_4 = Vector3.left * num2; Vector3 vector3_5 = Vector3.up * num2; Joint2DEditor.DrawAALine(target2 - vector3_4, target2 + vector3_4); Joint2DEditor.DrawAALine(target2 - vector3_5, target2 + vector3_5); }
void Start() { relativeJoint = GetComponent <RelativeJoint2D> (); // This test produces crazy low rotational inertia which makes the whole set-up unstable. // Explicitly set a reasonable inertia. relativeJoint.attachedRigidbody.inertia = 0.5f; }
private void Start() { joint = GetComponent <RelativeJoint2D>(); oldpos = transform.position; if (dockAtStart) { Dock(false); } }
void FreeBox() { if (ControlledBox != null) { ControlledBox.GetComponent <Rigidbody2D>().collisionDetectionMode = CollisionDetectionMode2D.Discrete; ControlledBox.enabled = false; ControlledBox = null; ControlledBoxStats = null; } }
void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "obstacle") { RelativeJoint2D newRelativeJoint = gameObject.AddComponent <RelativeJoint2D>(); DistanceJoint2D newDistanceJoint2D = gameObject.AddComponent <DistanceJoint2D>(); newDistanceJoint2D.maxDistanceOnly = true; newRelativeJoint.connectedBody = col.rigidbody; newDistanceJoint2D.connectedBody = col.rigidbody; col.rigidbody.constraints = RigidbodyConstraints2D.FreezeRotation; } }
private void PickUpObject() { // Enable the relative joint of the source RelativeJoint2D sourceRelativeJoint = pickingSource.GetComponent <RelativeJoint2D>(); sourceRelativeJoint.connectedBody = pickedUpObject.GetComponent <Rigidbody2D>(); sourceRelativeJoint.enabled = true; pickedUpObject.transform.parent = pickingSource.transform; //RepositionPickedUpObject(); }
public void ReleasePickedUpObject() { pickedUpObject.GetComponent <Rigidbody2D>().gravityScale = pickedUpObjectInitialGravityScale; // Disable the relative joint of the source RelativeJoint2D sourceRelativeJoint = pickingSource.GetComponent <RelativeJoint2D>(); sourceRelativeJoint.enabled = false; sourceRelativeJoint.connectedBody = null; pickedUpObject.transform.parent = null; pickedUpObject = null; }
////////////////////////////////////////////////////////////////////////// private void Awake() { m_Joint = GetComponent <RelativeJoint2D>(); if (m_Joint == null) { enabled = false; return; } m_RigidBody = m_Joint.connectedBody; if (m_RigidBody == null) { enabled = false; return; } m_PrevRotation = m_RigidBody.rotation; }
public bool HasPieceAttached() { if (_attachedPiece != null) { RelativeJoint2D attachedJoint = _attachedPiece.GetComponent <RelativeJoint2D>(); if (_attachedJoint != attachedJoint) { _attachedJoint = null; _attachedPiece = null; } return(_attachedJoint != null); } return(false); }
public static int get_maxTorque(IntPtr l) { int result; try { RelativeJoint2D relativeJoint2D = (RelativeJoint2D)LuaObject.checkSelf(l); LuaObject.pushValue(l, true); LuaObject.pushValue(l, relativeJoint2D.maxTorque); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public void Start() { var target = GetComponent <Rigidbody2D>(); if (target == null) { Destroy(this); return; } FixedJoint = target.gameObject.AddComponent <RelativeJoint2D>(); FixedJoint.autoConfigureOffset = false; FixedJoint.connectedBody = SourceRb; //FixedJoint.anchor = transform.localPosition - target.transform.position; //FixedJoint.distance = 1; //FixedJoint.autoConfigureDistance = false; }
void CatchBox(GameObject Target) { if (Target != null) { ControlledBoxStats = Target.GetComponent <BoxStats>(); ControlledBox = Target.GetComponent <RelativeJoint2D>(); if (ControlledBoxStats.State.State == BoxState.Losted) { FreeBox(); } else { ControlledBox.GetComponent <Rigidbody2D>().collisionDetectionMode = CollisionDetectionMode2D.Continuous; ControlledBox.connectedBody = GetComponent <Rigidbody2D>(); ControlledBox.enabled = true; } } }
public static int set_angularOffset(IntPtr l) { int result; try { RelativeJoint2D relativeJoint2D = (RelativeJoint2D)LuaObject.checkSelf(l); float angularOffset; LuaObject.checkType(l, 2, out angularOffset); relativeJoint2D.angularOffset = angularOffset; LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public static int set_maxForce(IntPtr l) { int result; try { RelativeJoint2D relativeJoint2D = (RelativeJoint2D)LuaObject.checkSelf(l); float maxForce; LuaObject.checkType(l, 2, out maxForce); relativeJoint2D.maxForce = maxForce; LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
private void Start() { ikpicker = gameObject.GetComponent <IKPicker>(); newPosition = Vector3.zero; var cameraPose = Camera.main.ScreenToWorldPoint(Input.mousePosition); //var cameraPose = Camera.main.ViewportToWorldPoint(Input.mousePosition); aim.position = new Vector3(cameraPose.x, cameraPose.y, 0.0f); Cursor.visible = false; recoilArm = GameObject.FindGameObjectWithTag("RecoilArm").GetComponent <Rigidbody2D>(); aimDirectionArm = recoilArm.transform.GetChild(0); recoilJoint = recoilArm.GetComponent <RelativeJoint2D>(); InitWeapon(); //Debug.Log(Mathf.Sin(30f * Mathf.Deg2Rad)); //Mathf.Sin() }
public void AttachPiece() { if (_attachedPiece == null) { return; } RelativeJoint2D attachedJoint = _attachedPiece.GetComponent <RelativeJoint2D>(); if (_attachedJoint == attachedJoint) { //_attachedPiece.Unattach(); Destroy(_attachedJoint); _attachedPiece.gameObject.layer = _vehicleLayer; _attachedPiece.AttachToRB(_attachedOverlapping, _playerController); _attachedPiece = null; _attachedJoint = null; } }
public void OnSceneGUI() { RelativeJoint2D target = (RelativeJoint2D)this.target; if (target.enabled) { Vector3 start = (Vector3)target.target; Vector3 end = (target.connectedBody == null) ? Vector3.zero : target.connectedBody.transform.position; Handles.color = Color.green; Joint2DEditor.DrawAALine(start, end); float num = HandleUtility.GetHandleSize(end) * 0.16f; Vector3 vector3 = (Vector3)(Vector3.left * num); Vector3 vector4 = (Vector3)(Vector3.up * num); Joint2DEditor.DrawAALine(end - vector3, end + vector3); Joint2DEditor.DrawAALine(end - vector4, end + vector4); float num2 = HandleUtility.GetHandleSize(start) * 0.16f; Vector3 vector5 = (Vector3)(Vector3.left * num2); Vector3 vector6 = (Vector3)(Vector3.up * num2); Joint2DEditor.DrawAALine(start - vector5, start + vector5); Joint2DEditor.DrawAALine(start - vector6, start + vector6); } }
public void Bind(BindEngine target) { if (boundObjects.Contains(target)) { return; } ; // Create a relative (angle and distance preserving) joint between the two objects. RelativeJoint2D joint = gameObject.AddComponent <RelativeJoint2D>(); joint.connectedBody = target.gameObject.GetComponent <Rigidbody2D>(); joint.enableCollision = false; Debug.Log(string.Format("BindEngine: binding objects {0} and {1}", gameObject.name, target.gameObject.name)); bindJoints.Add(joint); target.bindJoints.Add(joint); boundObjects.Add(target); target.boundObjects.Add(this); CreateBindDisplay(target); }
void OnCollisionEnter2D(Collision2D other) { if (_player.onRope == null && _player.onLadder == false) { if (other.gameObject == _player.gameObject) { _player.onRope = gameObject; _player.transform.parent = transform; _player.GetComponent <Collider2D>().isTrigger = true; RelativeJoint2D _playerHJ = _player.gameObject.AddComponent <RelativeJoint2D>(); _playerHJ.enableCollision = false; _playerHJ.maxForce = 200; _playerHJ.maxTorque = 200; _playerHJ.autoConfigureOffset = false; _playerHJ.linearOffset = new Vector2(0.2f, 0f); _playerHJ.angularOffset = 0; _playerHJ.connectedBody = _rb; ClimbAnimation.ResetTrigger("Jump"); ClimbAnimation.SetTrigger("Climbing"); } } }
private StickmanPart CreatePart(string partName, StickmanPart parent, float mass, int limits, int angle = 0) { StickmanPart part = StickmanPart.Create(partName, mass, partName); if (parent == null) //spine { part.transform.parent = base.transform; part.transform.localPosition = Vector3.zero; } else { part.transform.parent = parent.transform; part.transform.localPosition = new Vector3(0f, -parent.Length); HingeJoint2D joint = part.gameObject.AddComponent <HingeJoint2D>(); joint.connectedBody = parent.GetComponent <Rigidbody2D>(); joint.useLimits = true; JointAngleLimits2D limits2 = new JointAngleLimits2D { min = -limits / 2f, max = limits / 2f }; joint.limits = limits2; RelativeJoint2D springJoint = part.gameObject.AddComponent <RelativeJoint2D>(); springJoint.connectedBody = parent.GetComponent <Rigidbody2D>(); springJoint.maxForce = 0f; springJoint.maxTorque = GameOptions.maxRelativeTorque; //springJoint.frequency = this._spring; //springJoint.autoConfigureConnectedAnchor = true; //springJoint.dampingRatio = this.Damper; } part.transform.localEulerAngles = new Vector3(0f, 0f, (float)angle); return(part); }
public static Tween TweenAngularOffset(this RelativeJoint2D joint, float to, float duration) => Tweening.To(getter: () => joint.angularOffset, setter: angularOffset => joint.angularOffset = angularOffset, to, duration).SetTarget(joint);
void OnCollisionEnter2D(Collision2D collision) { if (recent_collision != collision.collider) { if (collision.rigidbody.CompareTag("Triangle")) { Triangle2 other = collision.rigidbody.GetComponent <Triangle2>(); other.recent_collision = collider; Vector2 displacement = collision.rigidbody.transform.position - transform.position; float distance = displacement.magnitude; if (distance < 0.7f) { float r_angle_a = Mathf.Atan2(displacement.y, displacement.x) * Mathf.Rad2Deg + 90f; float r_angle_b = r_angle_a - other.transform.rotation.z; r_angle_a -= transform.rotation.z; // Keep both angles within the bounds of -180 to +180 while (r_angle_a < -180f) { r_angle_a += 360f; } while (r_angle_a > 180f) { r_angle_a -= 360f; } while (r_angle_b < -180f) { r_angle_b += 360f; } while (r_angle_b > 180f) { r_angle_b -= 360f; } RelativeJoint2D j = gameObject.AddComponent <RelativeJoint2D>(); j.correctionScale = 1f; j.breakForce = stickyness; j.breakTorque = stickyness; j.connectedBody = other.rigidbody; j.autoConfigureOffset = false; // Check which side to attach on this triangle if (Mathf.Abs(r_angle_a) <= 60f) { // Attach to bottom of this triangle j.linearOffset = bottom_offset; j.angularOffset = 0f; } else if (r_angle_a > 0f) { // Attach to right side of this triangle j.linearOffset = right_offset; j.angularOffset = 120f; } else { // Attach to left side of this triangle j.linearOffset = left_offset; j.angularOffset = -120f; } // Check which side to attach on the other triangle if (Mathf.Abs(r_angle_b) >= 120f) { // Attach to bottom of the other triangle j.angularOffset -= 180f; } else if (r_angle_b > 0f) { // Attach to right of the other triangle j.angularOffset -= 60f; } else { // Attach to left of the other triangle j.angularOffset += 60; } } } } else { recent_collision = null; } }
// Start is called before the first frame update void Start() { rigid = GetComponent <Rigidbody2D>(); rj = GetComponent <RelativeJoint2D>(); }
// Use this for initialization void Start() { joint = GetComponent <RelativeJoint2D>(); }
void JointStrategy(ClothMass2D clothMass2D, RelativeJoint2D joint) { joint.linearOffset = clothMass2D.transform.localPosition - transform.localPosition; }
public static Tween TweenMaxForce(this RelativeJoint2D joint, float to, float duration) => Tweening.To(getter: () => joint.maxForce, setter: maxForce => joint.maxForce = maxForce, to, duration).SetTarget(joint);