addWheel method
Add a wheel
Implementation
int addWheel({
Body? body,
Vec3? position,
Vec3? axis,
Vec3? direction,
}){
Body wheelBody = body ?? Body(mass: 1, shape: Sphere(1.2));
wheelBodies.add(wheelBody);
wheelForces.add(0);
// Position constrain wheels
final pos = position?.clone() ?? Vec3();
// Set position locally to the chassis
final worldPosition = Vec3();
chassisBody.pointToWorldFrame(pos, worldPosition);
wheelBody.position.set(worldPosition.x, worldPosition.y, worldPosition.z);
// Constrain wheel
final ax = axis?.clone() ?? Vec3(0, 0, 1);
wheelAxes.add(ax);
final hingeConstraint = HingeConstraint(
chassisBody,
wheelBody,
pivotA: pos,
axisA: ax,
pivotB: Vec3.zero,
axisB: ax,
collideConnected: false,
);
constraints.add(hingeConstraint);
return wheelBodies.length - 1;
}