Car wheel behaviour using AngularVelocityMotor

Hi

I’m working on a car simulation. The car has a body and four wheels attached to the body using the AngularVelocityMotor components from the Physics samples pack.

I’m trying to get these wheels to turn and move the car along responding to controls at runtime. For example, if the user wants to increase speed, they increase an acceleration value which ultimately leads to some code that looks like the following in the WheelsSystem:

foreach (var (commandBuffer, joint) in
  SystemAPI.Query<DynamicBuffer<WheelCommand>, RefRW<PhysicsJoint>>())
{
  for (int i = 0; i < commandBuffer.Length, i++)
  {
    var command = commandBuffer[i];
    
    var constraints = joint.ValueRW.GetConstraints();
    for (int j = 0; j < constraints.Length; j++)
    {
      var constraint = constraints[j];
      if (constraint.Type == ConstraintType.AngularVelocityMotor)
      {
        constraint.Target.x = command.Power;
      }
      constraints[j] = constraint;
    }
    joint.ValueRW.SetConstraints(constraints);
  }
  commandBuffer.Clear();
}

This is a bit simplified but you get the gist - I read off the constraints and update the AngularVelocityMotor one according to the contents of the command.
The problem is that no matter what I do, the wheel doesn’t seem to turn at all. I’ve tried things like setting constraint.MaxImpulse = new float3(1000, 0, 0);, adjusting the SpringFrequency and DampingRatio values to various things, setting Min to -1000 and Max to 1000, but the wheel just never turns. It doesn’t even seem to twitch, so I question if the physics system is even picking up on the change… I know that the constraints are being updated as I can see them changing in the entity hierarchy inspector at runtime.

Is AngularVelocityMotor even the right type of PhysicsJoint to use for something like this?

Would greatly appreciate any tips!

EDIT:

I’m not sure exactly what’s happening, but if the car is on an incline and is gradually sliding down, then the wheels update perfectly. Somehow the physics system is going to sleep (?) if the vehicle is sitting still on flat ground? How do I force it to update?

EDIT2:

It looks like using Havok causes this, the entity is being put to sleep. I’ve tried using PhysicsWorldExtensions to apply a linear impulse of float3.zero but that isn’t waking it up.

EDIT3:

I have a temporary workaround in adding a HavokPhyisicsConfiguration to the subscene and unchecking “Enable Sleeping”, however this disables ALL sleeping… I would like to keep sleeping in for some entities but not for others.

FINAL EDIT:

Reposted as a bug here