Creating detailed control with DOFConstraint

DOFConstraint, also called the degree of freedom constraint, allows you to exactly control an object's linear and angular movement. We'll demonstrate how to use this constraint by creating an example where you can drive around a simple, car-like shape. This shape consists of a single rectangle that serves as the body and four spheres that serve as the wheels. Let's start by creating the wheels:

function createWheel(position) { var wheel_material = Physijs.createMaterial( new THREE.MeshLambertMaterial({ color: 0x444444, opacity: 0.9, transparent: true }), 1.0, // high friction 0.5 // medium restitution ); var wheel_geometry = new THREE.CylinderGeometry(4, 4, 2, 10); var wheel = new Physijs.CylinderMesh( ...

Get Learn Three.js - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.