Radius not matching with Physics2D.OverlapCircle

Avatar
  • updated
  • Answered

Hello, I'm very sure I must be doing something wrong, but for some reason,  when I draw a disc, the radius given doesn't match up with the overlapCircle or the drawgizmos. Both, the disc here and the gizmos have a radius of 5. 

Image 84

I'm not quite sure what I could be doing wrong. The prefab in use is scaled down to .6, but I wouldn't think if that was the reason the mismatch would be so much. The disc is a child of the prefab. I tried doing some multiplication as well to see if the .6 scaling was the reason, and I couldn't find a consistent multiple. Any ideas what I might be doing wrong?

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Answered

if you really need to keep the scale of parent objects, then this might help compensate for it:
rangeCircle.Radius = towerModel.Range / rangeCircle.transform.lossyScale.x;

Avatar
Freya Holmér creator
  • Under Review

hm, weird!
are you drawing it with a component? if so, could you take a screenshot of the inspector?

if you're drawing it in immediate mode - can you show the code you use to draw it?

Avatar
waffle stack dev

It's part a prefab. It's being drawn as a component, I'm setting the radius in code.

Avatar
Freya Holmér creator

the component will be affected by the scale of all parents above, which I'm guessing is what happens?

Avatar
Freya Holmér creator
  • Answer
  • Answered

if you really need to keep the scale of parent objects, then this might help compensate for it:
rangeCircle.Radius = towerModel.Range / rangeCircle.transform.lossyScale.x;

Avatar
waffle stack dev

Ah, ok. I pulled everything out and made it flat, the scaling was correct now. Maybe drawing in immediate mode would work better for me. You can mark this as answered. Thanks for this, this thing is awesome. I can finally move away from my terribly written shaders. 

Avatar
waffle stack dev
Quote from Freya Holmér

if you really need to keep the scale of parent objects, then this might help compensate for it:
rangeCircle.Radius = towerModel.Range / rangeCircle.transform.lossyScale.x;

Oh wow that worked perfectly,  thanks for that.

Avatar
Freya Holmér creator

glad it worked out!