Search Unity

Welded Meshes and Contact Headers - Help Please.

Discussion in 'Physics for ECS' started by Dapeos, Jul 2, 2020.

  1. Dapeos

    Dapeos

    Joined:
    Jun 27, 2013
    Posts:
    28
    Hi,
    Looking for any help or suggestions.
    In the first image I have a vehicle rolling down a single quad (Plane). Everything works as expected and car drives correctly.
    FlatPlane.png
    In the second Image I have a Mesh Collider with ModifyNarrowphaseContactsBehaviour applied to it. This fixes the direction of the Contact Normals and the car will roll properly down the slope. However when I apply gas, brakes or any additional force things do not work as expected.

    When I draw the debug Contacts what I see looks like the the wheel (cylinder collider) is being projected onto the mesh and I see many more contacts then expected.

    weldedMesh.png

    Thanks,
    Marc
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Yeah cylinders will produce a lot of contacts. How about instead you don't simulate wheels as bodies, but do a query? Something like 6. Use Cases/RaycastCar in the physics samples?
     
  3. Dapeos

    Dapeos

    Joined:
    Jun 27, 2013
    Posts:
    28
    Thanks for replying PetarmHavok.
    And also thanks for the examples, the RaycastCar Sample got me started on this journey in the fall.

    About two months ago I switched from using raycast suspension to using cylinder colliders connected via custom PhysicsJoints to the vehicle's Compound Collider.

    Only the Suspension force (Up Force) is handled by the Cylinder Colliders and Joints. Friction and restitution are set to zero.

    All other forces are still calculated; tractive force, cornering force, brake force, air resistance, rolling resistance, etc and applied using physicsVelocity.ApplyImpulse() in the appropriate job.

    This wasn't an easy choice as I had spent many hours on my raycast solution.

    However the Cylinder Collider + Joint suspension seemed to yield more consistent and realistic results and handled some collision edge cases I couldn't solve in a straight forward way with a raycast only solution.

    All of my testing til now has been using flat planes and I have been satisfied with the results. Only when driving on meshes is when I experience this crazy Contact behavior.

    I am willing to override any system to make this work or rebuild any meshes. Just need to be pointed in a general direction.
    Thanks,
    Marc
     
  4. Dapeos

    Dapeos

    Joined:
    Jun 27, 2013
    Posts:
    28
    When I say the Collider + Joint Suspension yielded better results, I am referring to the way the suspension reacted when the wheels are on risers or weight shifts due to acceleration + deceleration on a flat plane. Never noticed an issue rolling over speed bump, curbs etc as long as it was a separate mesh. Its only a problem with the Mesh Collider and the Cylinder Collider.

    Can I just overwrite the list of Contacts Headers? Like in ModifyNarrowPhaseContactsBehaviour.cs?
    Better question, Should I overwrite the list of Contact Headers. And are there any other examples I should be aware of before trying to craft something.
    Thanks,
    Marc
     
  5. Sima_Havok

    Sima_Havok

    Joined:
    Dec 16, 2019
    Posts:
    52
    I'll speculate what is happening here so value of analysis depends on how correct my assumptions are.

    When gas or breaks are applied the force is not applied in center of mass (most likely on wheels or where suspension is connected to the chassis). As a result the car's nose goes up or down and front or rare wheels are pushed harder into the ground.

    Not sure why but it looks like the cylinders end up in the slight penetration (I hope that bevel radius on cylinder colliders is greater than 0). In case when the wheel is going over the edge of the triangle the shortest distance to recover from penetration is not triangle normal but sideways. For that reason the contacts are built for the cap of the cylinder instead for the side face. So instead of getting 4 contact points for side face, 12+ are created for cylinder's cap face. Normals for those are sideways but since ModifyNarrowphaseContactsBehaviour is used they get turned into triangle normals.

    Thing that make me confused are that on the second screenshot numerous contacts for cylinder look like if the cylinder was rotated a bit around the axis in direction of the car movement. I would expect them to be in two lines but they form a projection of the circle on the plane.

    I made my guesses and I still have doubts what is going on so feel free to break my assumptions and make my conclusions irrelevant :) At least next iteration of analysis will be better.