protected bool AddConstraint() { vrPhysicsEngine physicsEngine = MiddleVR.VRPhysicsMgr.GetPhysicsEngine(); if (physicsEngine == null) { return(false); } if (m_PhysicsConstraint == null) { return(false); } bool addedToSimulation = false; // Cannot fail since we require this component. VRPhysicsBody body0 = GetComponent <VRPhysicsBody>(); VRPhysicsBody body1 = null; if (m_ConnectedBody != null) { body1 = m_ConnectedBody.GetComponent <VRPhysicsBody>(); } if (body0.PhysicsBody != null) { m_PhysicsConstraint.SetBody(0, body0.PhysicsBody); m_PhysicsConstraint.SetBody(1, body1 != null ? body1.PhysicsBody : null); addedToSimulation = physicsEngine.AddConstraint(m_PhysicsConstraint); if (addedToSimulation) { MiddleVRTools.Log(3, "[ ] The constraint '" + m_PhysicsConstraintName + "' was added to the physics simulation."); } else { MiddleVRTools.Log(0, "[X] Failed to add the constraint '" + m_PhysicsConstraintName + "' to the physics simulation."); } } else { MiddleVRTools.Log(0, "[X] The PhysicsBody of '" + name + "' for the fixed physics constraint '" + m_PhysicsConstraintName + "' is null."); } return(addedToSimulation); }