Search Unity

Known issues with ECS Sample Raycast Car demo?

Discussion in 'Physics for ECS' started by colin_young, Sep 15, 2021.

  1. colin_young

    colin_young

    Joined:
    Jun 1, 2017
    Posts:
    243
    I grabbed the latest sample code, updated to the latest packages (specifically Havok 0.6.0-preview.3 and entities 0.17.0.-preview.42) fixed up the breaking changes and verified everything was working. All 3 vehicles in the demo behave as expected (or as I expect, which is "reasonably game realistic"). Next, I tried to use the systems in my own project, with a custom vehicle mesh. I duplicated things as closely as possible, but the behavior was erratic -- vehicle was somersaulting and vaulting 100s of meters into the air. Assuming I had screwed up porting the code, I brought in the 4x4 model from the demo and that worked exactly as expected. So I thought I would take a video using Unity Recorder to get some help and when I did that, my custom vehicle simply flipped on it's back and then spun its wheels.

    I recognize that the vehicle mesh is simply a visual thing, but it is being used as reference for setting the transforms of the GameObjects that are used as inputs to the physics, so I decided to create the simplest possible vehicle: a cube for the chassis, and 4 more cubes, one for each wheel. I duplicated the transforms of each level to exactly match those for the corresponding GO in the 4x4 (working) model. I applied the same values for the chassis physics shape, and the same parameters for the physics body attached to the root of my new prefab, and same for vehicle authoring and physics components, so other than the visual mesh, it should be identical to the working model. I now have 3 vehicles in my scene: the 4x4 from the demo, my minimal vehicle and my custom mesh vehicle. When I run the scene, the 4x4 works as expected. My minimal vehicle launches straight up, at what appears to be a constant velocity, unaffected by gravity (gravity factor on the physics body is 1). The wheels also appear as if the the suspension is fully compressed. My custom mesh vehicle no longer performs somersaults, but instead immediately flips on its back, much as it did when recording video.

    Behavior is visually identical with either Unity Physics or Havok. Changing Solver Iteration Count from 4 to 8 has no effect (other than dropping the frame rate by 20% for Unity Physics). Changing the gravity factor has no effect on the minimal vehicle, nor does changing the value in physics setup. For the erratic custom mesh vehicle, changing either gravity or the gravity factor does appear to be consistent with the incorrect behavior - which at this point I think is due to relative transforms and physics parameters.

    Is there something obvious I've missed in setting up with the demo script?
     
  2. colin_young

    colin_young

    Joined:
    Jun 1, 2017
    Posts:
    243
    Further oddness: if I modify the X component of the transform on the graphical representation of the wheel (i.e. the thing that has no input into the physics calculations, mechanics > wheel > graphic), to place the wheels farther from the centerline of the chassis (i.e. wider vehicle stance), the simulation behaves stably, although the visuals are a bit off because the steering rotations are made around the y-axis of the graphic representation's parent.

    If I instead change the x-translation of the wheel (i.e. mechanics > wheel), the simulation is also stable, but in this case the wheels start out in the offset position (i.e. with the x-offset) and gradually move inwards to the "proper" position (i.e. where they would be without the x-offset).

    In these configurations, if I try to use Unity Recorder, gravity doesn't seem to apply and the vehicle just hangs in the air.

    Something odd is going on in the code.
     
  3. colin_young

    colin_young

    Joined:
    Jun 1, 2017
    Posts:
    243
    Mystery solved (partially): turns out I did in fact have box colliders on my graphic-only wheels. Removing that fixes the issues I was seeing. My other vehicle is likely due to some balance issues with the physics bodies.
     
    steveeHavok likes this.