public void OnSceneGUI() { ChipmunkPivotJoint joint = target as ChipmunkPivotJoint; if (joint != null && joint._handle == IntPtr.Zero) { SetupUndo("edited ChipmunkPivotJoint"); Transform t = joint.transform; Vector3 pivot = t.TransformPoint(joint.pivot); Vector2 pivotDelta = DotHandle(pivot) - (Vector2)pivot; if (pivotDelta != Vector2.zero) { joint.pivot = t.InverseTransformPoint((Vector2)pivot + pivotDelta); EditorUtility.SetDirty(target); } } }
protected void Update() { // Works for the mouse or a single touch. If doing multitouch, replace with with a loop over Input.touches // and adapt accordingly if (Input.GetMouseButtonDown(0)) { //Debug.Log ("mouse: "+ Input.mousePosition + " position: " + GetPosition(Input.mousePosition)); ChipmunkNearestPointQueryInfo info; Chipmunk.NearestPointQueryNearest(mouseBody.position, fingerThickness, out info); //Debug.Log ("Grabbed shape: " + info.shape); if (info.shape != null) { if (info.shape.body == null) { // We clicked on a static shape. You can't drag those! return; } grabbedShape = info.shape; mouseConstraint = mouseBody.gameObject.AddComponent(typeof(ChipmunkPivotJoint)) as ChipmunkPivotJoint; mouseConstraint.bodyB = grabbedShape.body; mouseConstraint.pivot = Vector2.zero; // high but not infinite. You can push heavy things, but not force yourself through things. mouseConstraint.maxForce = 1e3f; // 60f = the approximate intended frame rate mouseConstraint.errorBias = Mathf.Pow(1.0f - 0.15f, 60f); } } if (Input.GetMouseButtonUp(0)) { // remove mouse constraint. Destroy(mouseConstraint); } }