Skip to content

Physics Constraint Hinge

App: apps/physics_constraint_hinge/

Demonstrates a hinge constraint: a door body anchored at its hinge point. Press Space to apply an impulse to a sphere that pushes the door open. Uses an FPS camera (WASD + mouse look) loaded from a blend.

Terminal window
% ./plume3d physics_constraint_hinge
KeyAction
WASDMove FPS camera
Mouse dragLook around
SpaceLaunch sphere / push door
  • Loads Models/HingeExample.blend and instantiates GameCamera, GameLight, Environment (static walls/floor), Door (hinge-constrained dynamic body), and Sphere.
  • Finds the door node by Scene.findNodeById("door").
  • Space launches the sphere toward the door; the hinge constraint limits rotation to one axis so the door swings open.
  • Uses Physics.addImpulseAtPoint to apply an off-center impulse that creates swing torque.
  • FPS camera from blend via FPSCamera.fromCamera.
  • Shadow mapping enabled.
// Apply impulse at a point offset from door center
if (Input.keyJustPressed("space")) {
var pos = _doorNode.getPosition()
Physics.addImpulseAtPoint(_doorNode,
0, 0, -50, // impulse direction
pos[0] + 2, pos[1], pos[2]) // off-center point
}

Create Models/HingeExample.blend with the Plume3D addon:

ObjectClassRigid BodyNotes
EnvironmentEnvironment collectionStatic walls/floor
DoorDoor objectActive, BoxAdd a Rigid Body Constraint: Hinge, anchored at door edge
SphereSphere objectActive, SphereLaunched by Space
CameraGameCameraTag: game_camera
LightGameLightTag: game_light
  • PhysicsaddImpulseAtPoint, addImpulse.
  • ScenefindNodeById.
  • ResourceloadBlend.
  • GraphicssetLights, setShadowMappingEnabled.