Cannon vehicle moving on its own

I’m implementing a 3D truck simulator and I’m facing a problem with the trailer: it moves on its own, both when parked and when hitched to a semi-truck.

Here are some details and context:

  • The ground is perfectly flat and horizontal
  • The wheels have friction (frictionSlip: 1.4)
  • There’s no force being applied to the vehicle (trailer)

Expectation: The trailer should remain stationary (still).

Reality: The trailer moves on the Z axis (see panel with vehicle coordinates).

Important: If we symmetrically position one axle at each end of the trailer, then the self-movement stops

What am I missing?

Minimum prototype: https://codepen.io/rguidolini/pen/MYaKPLr

1 Like

wheels drift with/against chassis

  • avoid rounding error with direct assign operator. Demonstrates need for better rig setup or more production-ready simulation transference.
  • avoid self-collision with layer/group/mask exclusion pairs. Or as your code evolves not that either.
// use = instead of copy()
chassisMesh.position = chassisBody.position
//chassisMesh.position.copy(chassisBody.position);
chassisMesh.quaternion = chassisBody.quaternion
//chassisMesh.quaternion.copy(chassisBody.quaternion);

Sorry I am busy with a job.

1 Like

Sorry but your comment doesn’t make sense to me. In JavaScript, this would make the chassisMesh.position property point to the exact same object in memory as chassisBody.position. This is problematic because three.js and cannon.js would be trying to manipulate the same object, leading to unpredictable behavior and likely breaking the simulation.

Am I missing anything?

Sorry! The issue seems to be groundBody.position.y = -0.1; and setting this to 0.1 (or some other extreme value) illustrates the collision. After setting it to 0.1 for the thin ground, I see a stable Angle.x. But extreme values cause the car to drop into the thin ground more or less. I assume having all of the wheels at the back of the trailer causes the imbalanced vehicle to drift off center as it intersects the ground. It was difficult to see, because the camera re-centers on the car so it appears the cones drift.

In cases where there is no ground, I see the car fall freely at perfect coordinates. However, sometimes it sporadically pulses in size… again, presumably from self-intersection? I also saw as it rotated in smooth 360 freefall the Z report -90 and 90 without any intermediate steps.

It seems related to the combination of thin ground contact with a lopsided trailer that sporadically impacts itself.

1 Like