Search Unity

Draw colliders in game?

Discussion in 'Physics' started by Cremator, Jul 17, 2019.

  1. Cremator

    Cremator

    Joined:
    Dec 23, 2015
    Posts:
    11
    Hello everyone, I'm referring to you as i'm stuck with something that looks fairly simple to accomplish.

    I'm making an editor in which the user can create colliders and edit them, my issue is that I can't find a simple way to display colliders in game.

    I know everything related with Gizmos and Debugs can't appear on screen at runtime, and the LineRenderers seems too over complicated for the simple task I'm trying to achieve.

    The solution I found is to create a primitive and scale it to the colliders dimension to create a display of it, it works fine for the sphere and cube colliders however the two caps of a capsule are stretched out when I edit its scale. Have you ever had this limitations? if yes what solution have you found?
     
  2. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Not a solution exactly but have you considered making your capsule display more complicated? You could combine 2 spheres and a cube together if your shader allows for that kind of overlapping, and then you could stretch the cube to match the height of the capsule collider. Since you have the radius you can also do some calculations to find the positions of the 2 spheres in regards to the endpoints of the capsule. This would require your display script to have multiple types/cases, and it should track when the case is a capsule collider--if so, it would employ the special logic instead of regular scaling.
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    I assume you let them edit a mesh that later goes to be a mesh collider.

    Whats wrong with the mesh renderer?, it's exactly what its for.
     
  4. Cremator

    Cremator

    Joined:
    Dec 23, 2015
    Posts:
    11
    Sorry for answering that late but thank you guys I've found a way, I actually draw line renderers make it a shape (cube sphere etc...) then I adjust its size accordingly to the collider's size values thank you all anyway!