Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Efficient "constant screen size" colliders

Discussion in 'Physics for ECS' started by BugsBuggy, Aug 7, 2023.

  1. BugsBuggy

    BugsBuggy

    Joined:
    Apr 24, 2014
    Posts:
    12
    Hey everyone, I am doing a 3d modeling application. I need constant screen size colliders for vertices and edges, so they are clickable from every zoom level. The current implementation is to updates all of the colliders every frame that the camera moves, but that causes physics world rebuilds which is slow. Is there any simple solution that I am missing? The only thing I can come up with is to throttle the number of colliders updated every frame, but that would not be the simplest or best feeling solution.
     
  2. mgi388

    mgi388

    Joined:
    Jun 3, 2023
    Posts:
    4
    Not sure what you’re doing, but I am achieving constant screen size by just scaling transforms based on camera orthographic size. I do it before the transform system runs (because it seemed like a sensible place to do it) and I just let the physics system pick up the change in scale whenever it runs.

    I haven’t profiled so no idea how performant it is, but it appears to work at least.
     
  3. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    213
    You can uniformly scale colliders efficiently and without having to recreate the collider by using the entity's LocalTransform.Scale property.

    I assume that uniform scaling would be sufficient for your use case.
     
    mgi388 likes this.