Search Unity

multiple boxes for floor and a bouncy sphere problem

Discussion in 'Physics for ECS' started by argibaltzi, Sep 16, 2020.

  1. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    Hi
    I have a problem where i have a floor composed of boxes (lets say 10 boxes perfectly in a row), thats 10 entities with a box collider each

    i send a bouncy ball forward but sometimes it seems to get 2 collisions (1 hitting the top of a box and at the same time also colliding with the "corner" of the next box.

    It makes the bouncy ball jump backwards because of this.
    Is there anything i can do to prevent this? its "impossible" to hit the corner of the next box as the alignment is perfect for the boxes.

    The normal of the wrong bounce comes out as this ( i am sending the sphere forward on x axis only)
    float3(-0.4347691f, 0.900542f, 0f)

    Thanks!!
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Yeah this is expected because of the predictive contacts.Your options are:
    1. Switch to Havok physics, which has a solution for this called "welding".
    2. Try to come up with a fixup for contacts (using IContactsJob) by for example casting a sphere in the velocity direction and seeing if it will actually hit the provided normal. Some context for this can be found here https://forum.unity.com/threads/sph...se-on-contact-with-mesh-collider-edge.889963/.
    3. Wait a little while longer as we will try to provide the sample code for 2 in the coming releases, but I can't set the date or anything since it's still in early prototyping phase.
     
    Gen_Scorpius likes this.
  3. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    It seems 1) is the easiest? is there any info how to do this?
     
  4. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
  5. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    ok i will have a look steve thanks!
    just to make sure i understand correctly
    1. enable welding for (floor body tags) in havok config
    2. add the custom tag (floor body) on terrain floor objects
    3. no changes to sphere?
     
    steveeHavok likes this.
  6. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Yes, that should do it.
     
  7. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    i am using custom code, where do i put this body tag? do i add a new componentData or somewhere that exists already?
     
  8. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Add PhysicsCustomTags component data to your entities that need welding and that's it.
     
    argibaltzi likes this.
  9. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    it doesnt seem to work much better, even on the first bounce it will sometimes shoot up even though it had a forward velocity. the problem doesnt seem to appear as often though

    Is this welding technique supposed to minimize or eliminate the problem?

    Code (CSharp):
    1.   if (PixelData.TypeId == BlockType.Terrain)
    2.         {
    3.             Unity.Physics.PhysicsCustomTags tagData = new Unity.Physics.PhysicsCustomTags() { Value = PhysicsManager.Instance.TerrainBlocksBodyTag.Value };
    4.             dots.EntityManagerRef.AddComponentData<Unity.Physics.PhysicsCustomTags>(dots.ECSEntity, tagData);
    5.         }
    when i create terrain blocks i add this as discussed


    my settings are as simple as this

    EDIT: i noticed that my bowling balls now move on the floor nicely without any hiccups that i had before. The forward bouncy ball however does not seem to work as well, any ideas?
     
    Last edited: Sep 17, 2020
  10. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Maybe look at Bevel Radius and see if increasing it helps? To avoid penetrations to some extent... Also, do you need it to be bouncy? It could be that restitution causes problems as well...
     
    steveeHavok likes this.
  11. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    It seems the restitution is causing this problem, i guess welding can't fix this problem?


    Is it possible to use SimulationCallbacks and disable certain collisions whos normal is not Vector3.up for example?
    I had a look at a sample, i didnt see anything about normals or impulses
     
    Last edited: Sep 20, 2020
  12. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Yes, it is possible. Implement an IContactsJob, you'll get a ModifiableContactHeader and ModifiableContactPoint and you can tweak their normals. If you know your normals should all be pointing up, it should be fairly easy to do. Check ModifyNarrowphaseContactsBehaviour in the samples, it does some magic with normals, although it's probably too complicated for your case.