Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Sendatsu_Yoshimitsu · Aug 01, 2015 at 05:26 AM · mathcircleworldtoscreenpoint

Converting screen cordinates to position on circle

This is one of those issues which is trivial to draw and absurdly awkward to describe verbally, so please look forward to some absurdly bad MS Paint illustrations.

Now, I'm trying to write a system which will give me coordinates to position speech bubbles. When an NPC speaks, I convert their location in world space to screen space, and end up with a Vector2 screenPosition, which most closely approximates each NPC's location.

For the purposes of playability and making the dialogue easier to read, I want every dialogue bubble to eventually live somewhere in a circle around the player model, as illustrated in these lovely schematics.

Speech bubbles start out at screenPosition, the WorldToScreenCoordinates of the character speaking:

alt text

Bubbles get snapped to the position in said circle that is closest to their starting location:

alt text

So I'm really confused about how I need to accomplish this- there is no literal circle, it's just a conceptual space on the screen, so how do I actually derive a Vector2 coordinate representing "The closest point to this bubble's starting transform on a circle of r radius originating from screen center"?

circle2.png (14.1 kB)
circle1.png (23.5 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by tanoshimi · Aug 01, 2015 at 06:44 AM

Step 1: Calculate the vector representing the direction from the centre of the screen to the speech bubble

 Vector3 vec = speechBubble.position - screenCentre.position;

Step 2: Normalise it to unit length:

  vec.Normalise();

Step 3: Multiply it by the desired radius r:

 vec *= r;

Step 4: Since the vector now represents an "offset" from the screen centre, add the screen centre back:

 Vector3 correctPlaceToPutSpeechBubble = vec + screenCentre.position;
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 Sendatsu_Yoshimitsu · Aug 01, 2015 at 06:57 AM 0
Share

Holy cow, I can't believe it's so simple when you explain it- thank you very much!! This works perfectly :)

avatar image
0

Answer by maccabbe · Aug 01, 2015 at 06:41 AM

Define a ray from the center of the circle to the current position. Then get the point on the ray radius (R) away from origin. Something like

 Ray2D ray=new Ray(circleCenter, npcPosition-circleCenter);
 Vector2 newPosition=ray.GetPoint(radius)

http://docs.unity3d.com/ScriptReference/Ray2D.html

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

22 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 avatar image

Related Questions

Programmatically specifying a random point in an arc in front of the player 1 Answer

Circular motion via the mathematical circle equation? 4 Answers

Find distance around a circle, from center point and another point 2 Answers

How to make a wavy circle? 0 Answers

Launching object in circular motion 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