// Given two objects, with hangingBox below staticBox // apply a constraint on hangingBox so that it hangs on the staticBox // Try assigning a box object for each input!
// Create a child object that we can set up as our hinge varhingeObj = global.scene.createSceneObject("hinge"); hingeObj.setParent(hangingBox);
// First we use the child object as a constraint varhingeConstraint = hingeObj.createComponent("Physics.ConstraintComponent");
// Then we set up the constraint as a hinge hingeConstraint.debugDrawEnabled = true; hingeConstraint.constraint = Physics.Constraint.create(Physics.ConstraintType.Hinge);
// Attach our hinge to another Physics body hingeConstraint.target = staticBoxBody;
// Position the hinge hingeObj.getTransform().setLocalPosition(newvec3(-7.5, 7.5, 0))
// Tell the system to recalculate the simulation based on the above parameters hingeConstraint.reanchorTarget();
Constraint type used by a Constraint. See also: Constraint, ConstraintComponent.
Example