Search Unity

To change Scale and Collider radius in ECS Physic

Discussion in 'DOTS Physics' started by AlexandrBuryakov, Aug 5, 2019.

  1. AlexandrBuryakov

    AlexandrBuryakov

    Joined:
    May 30, 2018
    Posts:
    31
    Hello.
    1) How to change the object size?
    Found only such option:
    Code (CSharp):
    1.  
    2.     var entityManager = World.Active.EntityManager;
    3.     Entity sourceEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy ( go, World.Active );
    4.     BlobAssetReference<Unity.Physics.Collider> sourceCollider = entityManager.GetComponentData<PhysicsCollider> ( sourceEntity ).Value;
    5.     //Some code...
    6.     var instance = entityManager.Instantiate ( sourceEntity );
    7.     var cs = entityManager.GetComponentData<CompositeScale> ( instance);
    8.     cs.Value.c0.x = radius;
    9.     cs.Value.c1.y = radius;
    10.     cs.Value.c2.z = radius;
    11.     cs.Value.c3.w = 1;
    12.     entityManager.SetComponentData ( instance, cs );
    13.  
    14.     entityManager.SetComponentData ( instance, new PhysicsCollider { Value = sourceCollider } );
    15.  
    2) The size of a collider does not change. How to change the collider size?
    I correctly do?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,027
    From memory, collider scale is baked into the physics shape during conversion and can't easily be changed.

    You'd need to regenerate the collider.
     
  3. AlexandrBuryakov

    AlexandrBuryakov

    Joined:
    May 30, 2018
    Posts:
    31
    1) How it can be done?
    2) There is still a thought to have empty GameObject with a collider. Without restoration of a collider. To adjust a collider before converting.
    But I do not know how to calculate correctly the collider size. It is necessary to establish localScale as in CompositeScale?
    3) The second way will be more productive? (But it is necessary to store some settings separately.)
     
  4. mpforce1

    mpforce1

    Joined:
    Apr 4, 2014
    Posts:
    34
    Hi, just to add to this, in my current project we're using ECS and have found that the colliders generated using the conversion system don't change scale along with the Scale or NonUniformScale. However, they do move along with the Translation and Rotation. I would also like to know if:
    1) There is an existing API available that will allow us to create/modify the collider with expanded vertices?
    2) It is planned to make colliders scale along with the scale component in the future?
     
  5. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    70
    Scale is not yet represented in the PhysicsWorld, largely because it adds significant complexity and because non-uniform scale in particular is not applicable to certain use cases (spheres and capsules).

    The current situation is:
    * Any scale present in a game object is baked into the collider during the conversion system
    * The physics world only uses entity position and rotation after that point
    * Primitive colliders (sphere, capsule, box, cylinder) have properties allowing you to scale them inplace if desired

    What to expect in future:
    * Convex, Mesh and Terrain collider will likely offer a "scale" property or method to modify them inplace
    * We want to experiment with applying at least the _uniform_ scale from entities into the physics world each frame (but no concrete plan)

    Hope that helps
     
  6. Vicotin

    Vicotin

    Joined:
    Mar 18, 2014
    Posts:
    7
    lclemens and SteffenEichler like this.
  7. alvinwan

    alvinwan

    Joined:
    Jan 21, 2018
    Posts:
    34
  8. mpforce1

    mpforce1

    Joined:
    Apr 4, 2014
    Posts:
    34
    Hello again, has there been any progress in providing a scale method for mesh colliders? If not could you provide some guidance on how scaling can be done? I'm having trouble figuring out how to extract the vertex and triangle arrays from an existing mesh collider. Additionally, the MeshCollider.Create method wants a filter and material but mesh collider only seems to expose a filter. Thanks.
     
  9. KoomZog

    KoomZog

    Joined:
    Apr 7, 2020
    Posts:
    4
    I also ran into this issue. Having changes to mesh scale also affect the collider scale would be useful to me.

    I circumvented the problem by deleting the old entity and spawning a new one from a modified prefab with the scale I wanted. It's not pretty, but it works.
     
  10. meanfox

    meanfox

    Joined:
    Apr 9, 2020
    Posts:
    25
    Another vote for scale to work with physics please.
     
  11. Koamr

    Koamr

    Joined:
    Jul 19, 2013
    Posts:
    8
    Hi, any update on scaling the collider?
     
  12. DomingoGD

    DomingoGD

    Joined:
    Jan 28, 2018
    Posts:
    15
    Up.

    Also Looking for a way to scale the collider.

    Hi Rory, any hints how to modify the primitives scale property ? (after entities are instantiate via SetComponentdata()).
     
  13. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    You typically GetGeometry() (say SphereGeometry or BoxGeometry), change what you want (scale the radius or size) and then SetGeometry().
     
  14. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    480
    VolatileCoder likes this.
  15. VolatileCoder

    VolatileCoder

    Joined:
    Sep 21, 2014
    Posts:
    18
    In the demo, it's updating the radius property of a sphere collider. This works fine for simple colliders (spheres, cubes, etc), but would this work when scaling a mesh or convex hull collider?

    We really need a utility function for collider transformations/deformations at runtime.
     
  16. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    480
    Uniform runtime scale is something we are planning on investigating, however at the minute for convex hulls or meshes the easiest thing is to modify the input geometry and recreate.
    Note that non-uniform runtime scale is not being considered.
     
unityunity