Example #1
0
    public override void StartEvent()
    {
        // get a physics body using the Physics World GetPhysicsBodyFromPosition
        PhysicsBody body = PhysicsWorld.BodyAtPosition(Input.mousePosition);

        // if not null
        if (body != null)
        {
            // set the bodyAnchor to the body and set active to true
            BodyAnchor = body;
        }
    }
    public override void StartEvent()
    {
        PhysicsBody body = PhysicsWorld.BodyAtPosition(Input.mousePosition);

        if (body != null)
        {
            List <PhysicsJoint> deletion = new List <PhysicsJoint>();
            foreach (PhysicsJoint joint in m_physicsWorld.joints)
            {
                if (joint.BodyA == body || joint.BodyB == body)
                {
                    deletion.Add(joint);
                }
            }
            deletion.ForEach(joint => m_physicsWorld.joints.Remove(joint));
            m_physicsWorld.bodies.Remove(body);
            Destroy(body.gameObject);
        }
    }
Example #3
0
    public override void StopEvent()
    {
        if (BodyAnchor != null)
        {
            // get a physics body using the Physics World GetPhysicsBodyFromPosition
            PhysicsBody body = PhysicsWorld.BodyAtPosition(Input.mousePosition);

            // if not null and the body isn’t the body anchor
            if (body != null && BodyAnchor != body)
            {
                // set float restLength to (bodyAnchor – body) magnitude
                float restLength = (BodyAnchor.Position - body.Position).magnitude;
                // call the create function passing (bodyAnchor, body, restLength and m_k)
                Create(BodyAnchor, body, restLength, m_springPower.value);
            }
        }
        // set bodyAnchor to null and set active to false
        BodyAnchor = null;
    }
 public override void StartEvent()
 {
     BodySelect = PhysicsWorld.BodyAtPosition(Input.mousePosition);
 }