void Create(PhysicsBody bodyA, PhysicsBody bodyB, float restLength, float springPower) { PhysicsSpringJoint joint = new PhysicsSpringJoint(); // set the joint bodies, the rest length and k joint.BodyA = bodyA; joint.BodyB = bodyB; joint.RestLength = restLength; joint.SpringPower = springPower; // add the joint to the physics world joints m_physicsWorld.joints.Add(joint); }
private void Update() { m_lineRenderer.enabled = (BodySelect != null); if (m_lineRenderer.enabled) { Vector2 position = Camera.main.ScreenToWorldPoint(Input.mousePosition); m_lineRenderer.SetPosition(0, BodySelect.Position); m_lineRenderer.SetPosition(1, position); if (BodySelect.Type == BodyTypeEnumRef.eType.Dynamic) { Vector2 force = PhysicsSpringJoint.SpringForce(position, BodySelect.Position, 0.01f, 30.0f); BodySelect.ApplyForce(force, PhysicsBody.eForceMode.IMPULSE); } else { BodySelect.Position = position; } } }