I have a RigidVehicle setup (based off cannon’s own example, except I define the car as facing positive z) and it does work as expected. But occasionally, the back wheels will be incorrectly rotated along the z axis, this matches what the underlying sphere body is doing too, so it doesn’t appear to be related to mesh issues.
Occasionally the wheel will correct itself, or slide back into an awkwardly slightly tilted rotation.
What could be the issue? Is this something that just comes with the territory?
let rotation = new Quaternion().setFromEuler(...incomingRotation)
let material = new Material("wheelMaterial")
let contactMaterial = new ContactMaterial(material, world.defaultMaterial, {
friction: 100,
restitution: .1,
contactEquationStiffness: 1000
})
let chassisBody = new Body({
mass,
position: position ? new Vec3(...position) : undefined,
quaternion: rotation
})
let emptyOffset = new Vec3()
let emptyQuaternion = new Quaternion()
for (let [shape, offset = emptyOffset, quaternion = emptyQuaternion] of chassis) {
chassisBody.addShape(
shape,
offset.vadd(centerOfMassAdjust),
quaternion
)
}
let vehicle = new RigidVehicle({ chassisBody })
let direction = new Vec3(0, -1, 0) // down
let axis = [-1, -1, 1, 1]
for (let [index, { position, radius }] of wheels.entries()) {
let shape = new Sphere(radius)
let body = new Body({
shape,
mass,
material,
angularDamping: .99,
quaternion: rotation,
})
vehicle.addWheel({
body,
position: new Vec3(...position).vadd(centerOfMassAdjust),
axis: new Vec3(axis[index], 0, 0),
direction
})
}
// wheels like this:
const wheels: Wheel[] = [
{
position: [wheelX, wheelY, .7],
radius
},
{
position: [-wheelX, wheelY, .7],
radius
},
{
position: [wheelX, wheelY, -.7],
radius
},
{
position: [-wheelX, wheelY, -.7],
radius
}
]
<group ref={wheelsRef}>
<mesh
castShadow
receiveShadow
geometry={nodes["wheel-front-left"].geometry}
>
<primitive
attach="material"
object={materials.colormap}
wireframe={Config.DEBUG}
/>
</mesh>
<mesh
castShadow
receiveShadow
geometry={nodes["wheel-front-right"].geometry}
>
<primitive
attach="material"
object={materials.colormap}
wireframe={Config.DEBUG}
/>
</mesh>
<mesh
castShadow
receiveShadow
geometry={nodes["wheel-back-left"].geometry}
>
<primitive
attach="material"
object={materials.colormap}
wireframe={Config.DEBUG}
/>
</mesh>
<mesh
castShadow
receiveShadow
geometry={nodes["wheel-back-right"].geometry}
>
<primitive
attach="material"
object={materials.colormap}
wireframe={Config.DEBUG}
/>
</mesh>
</group>
