Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by bcombes · Feb 07, 2014 at 06:33 PM · unity 2dcollider 2dworld spacein-engine

How to get correct scale for CircleCollider2D radius?

I working on a pool type 2D game using the new Unity 4.3 2D tools and it appears that I've run into a little ditch. To effectively make a shot, I need to locate a point on the circumference of the ball and target same. The code I use to do this is shown below;

 Vector2 startPoint  = ConvertTo2D(source.transform.position);
 Vector2 targetPoint = ConvertTo2D(target.transform.position);
 Vector2 lineOfSight = targetPoint - startPoint;
 
 lineOfSight.Normalize();
 if(source.collider2D is CircleCollider2D) {
   startPoint = startPoint + lineOfSight *   (CircleCollider2D)source.collider2D).radius;
 } 

The problem is that the dimension returned for radius from the circle collider is much larger than expected an it appears that this is based on the physics engine simulation and not world space dimensions. How can I easily convert dimensions from physics engine scale to world space?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by mikembley · Jul 16, 2015 at 09:15 AM

The best way i have found is to use the largest localscale axis

 float scaledRadius = Mathf.Max(transform.localscale.x, transform.localscale.y);
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by mgsteinkamp · Apr 22, 2014 at 02:14 AM

Not sure if this is what you're looking for, but the radius is relative to the object that it is attached to and should be preset to .5. To convert to world space you would multiply the game object's diameter by the collider's radius.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by bcombes · Apr 22, 2014 at 04:34 PM

Thanks for the response, I eventually found another way around this that didn't involve physics calculations.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jaxx0rr · Jul 18, 2014 at 05:53 AM 2
Share

and you don't wanna share it right ?

avatar image
0

Answer by Zarkend · Apr 10, 2019 at 06:59 AM

I know this is an old question, but just answering for future reference.

Check the parent's Scale since it seems that the collider radius scale with it (pretty strange behaviour).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sliding in a 2D side scrolling game? 1 Answer

How can I make 2d sprites for Unity ? 1 Answer

can i insert an image to be the background of my 2d game if so how ? 1 Answer

Drag and drop Word game 1 Answer

Refreshing the Polygon Collider (2D) upon sprite change? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges