Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Kulahan · Sep 20, 2011 at 04:24 PM · rotationjavascriptminimapobjective

Minimap issue

Here's the issue: I have a circular minimap. On that minimap, I want to display objective locations. However, if you're far enough away that the objective would normally be drawn past the edge of the minimap, I just want it to put a symbol at the edge of the map. Now, I've already got the trigger set up with the following code:

         if((Mathf.Sqrt(((objPos.x) * (objPos.x)) + ((objPos.y) * (objPos.y)))) > 65)//if the objective is more than 65 pixels from the center of the map...
     {
         var bill = Mathf.Tan(objPos.x/objPos.y);
         var x = Mathf.Cos(bill);
         var y = Mathf.Sin(bill);
         GUI.DrawTexture(Rect(x - 25,Screen.height - y - 25,50,50),HighObjectiveIcon); // draw the actual icon on the screen
     }

EDIT: I've updated the code a bit (ignore the awesome naming conventions, I was in a rush, haha). This is CLOSE, but not exact. It now is correctly triggering and redrawing the dot as soon as it goes outside of the circle or comes back into it, but instead of leaving it at the edge, it just draws it in the corner of the screen, haha. Thoughts?

Comment
Add comment · Show 1
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 syclamoth · Sep 21, 2011 at 01:57 PM 0
Share

Your code looks weird. I don't think you're telling it to do what you think you're telling it to do.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by syclamoth · Sep 21, 2011 at 09:43 AM

Assuming your minimap is circular (not square like I initially assumed it was), you can try converting the coordinates to a circular coordinate system, and then limiting the radius before converting it back to a cartesian one! All of the functions for this are in the Mathf class- you are already using the one to get the radius in your script above, so all you need is the angle- determined by

 Mathf.Atan2(objPos.x, objPos.y);

Now you can change the radius back to 65 (your state limit) and convert them back into the cartesian coordinates that your typical screen outside of submarine sonar displays can understand, using Sin and Cos.

Comment
Add comment · Show 5 · 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 Kulahan · Sep 21, 2011 at 01:26 PM 0
Share

I tried using your method as well, and I ran into the same issue as I did in my updated code above.

avatar image syclamoth · Sep 21, 2011 at 02:02 PM 0
Share

Give this a shot- (assu$$anonymous$$g objPos is a vector2)

 // define this at the top of your script!
 var maxAngle = 65;
 var radius = Vector2.Distance(objPos, Vector2.zero);
 var angle = $$anonymous$$athf.Atan2(objPos.x, objPos.y);

 radius = $$anonymous$$athf.Clamp(0, maxAngle, radius)
 Vector2 properPosition = Vector2(radius * $$anonymous$$athf.Cos(angle), radius * $$anonymous$$athf.Sin(angle));

Now use properPosition where you would have used objPos earlier. Your code above is pretty confusing- I'm not actually sure what it does, but I'm pretty sure it's not what you want. This way, you use the same bit of code to display your $$anonymous$$imap icon whether it's on the map or not- you don't need any special cases! (unless you wanted to use a different picture if it was off the map, in which case you would put an if statement in there somewhere changing the texture).

avatar image Kulahan · Sep 21, 2011 at 02:22 PM 0
Share

Haha, you'll have to forgive me if I seem a bit slow at this - the only language I've ever written in before was a few months of C#, and I was sorta "throw in" to a game written almost entirely in javascript. In any case, I get that I won't need any more special cases (very awesome, by the way), but are you saying I won't need to define objPos anymore? Because currently I'm using

 var objPos = camera.WorldToScreenPoint(ObjectiveHigh.Transform.Position);

This is no longer necessary?

So, basically, this is what I have now: var HighObjectives = GameObject.FindGameObjectsWithTag("ObjectiveHigh"); var LowObjectives = GameObject.FindGameObjectsWithTag("ObjectiveLow");

 for (var ObjectiveHigh : GameObject in HighObjectives)  { 
     radius = $$anonymous$$athf.Clamp(0, maxAngle, radius);
     Vector2 properPosition = Vector2(radius * $$anonymous$$athf.Cos(angle), radius * $$anonymous$$athf.Sin(angle));
     var objPos = camera.WorldToScreenPoint(ObjectiveHigh.transform.position);
     
     if(($$anonymous$$athf.Sqrt(((properPosition.x) * (properPosition.x)) + ((properPosition.y) * (properPosition.y)))) > 65)//if the objective is more than 65 pixels from the center of the map...
     {
         var bill = $$anonymous$$athf.Tan(objPos.x/objPos.y);
         var x = $$anonymous$$athf.Cos(bill);
         var y = $$anonymous$$athf.Sin(bill);
         GUI.DrawTexture(Rect(x - 25,Screen.height - y - 25,50,50),HighObjectiveIcon); // draw the actual icon on the screen
     }
 }

And defined above, I have:

 var HighObjectiveIcon : Texture;
 var LowObjectiveIcon : Texture;
 var maxAngle = 65;
 var radius = Vector2.Distance(objPos, Vector2.zero);
 var angle = $$anonymous$$athf.Atan2(objPos.x, objPos.y);
avatar image syclamoth · Sep 21, 2011 at 02:29 PM 0
Share

No, the radius and angle are the polar coordinates deter$$anonymous$$ed by the cartesian coordinates of your $$anonymous$$imap! I was assu$$anonymous$$g that objPos (which, by the way, you definitely still need to define- when I said at the top of the script, I only meant the maxRadius bit, sorry) was defined in terms of the middle of your $$anonymous$$imap. For any of this code to work, you first need to have a coordinate system which is centered on the middle of your $$anonymous$$imap.

if you're more familiar with C#, I'd be more than happy to work in that language ins$$anonymous$$d- I'm much better with it, since it's pretty much all I ever work with!

avatar image Kulahan · Sep 21, 2011 at 03:46 PM 0
Share

Ok, so I got the code to fit into $$anonymous$$e just fine, but now it's just not drawing the dot at all! haha. Anyways, here's what I've got.

 for (var ObjectiveHigh : GameObject in HighObjectives)  { 
     var objPos = camera.WorldToScreenPoint(ObjectiveHigh.transform.position);//find location
     var maxAngle = 65;
     var radius = Vector2.Distance(objPos, Vector2.zero);
     var angle = $$anonymous$$athf.Atan2(objPos.x, objPos.y);
     radius = $$anonymous$$athf.Clamp(0, maxAngle, radius);
     var properPosition : Vector2;
     properPosition = Vector2(radius * $$anonymous$$athf.Cos(angle), radius * $$anonymous$$athf.Sin(angle));
     
     if(($$anonymous$$athf.Sqrt(((objPos.x) * (objPos.x)) + ((objPos.y) * (objPos.y)))) > 65)//if the objective is more than 65 pixels from the center of the map...
     {
         var bill = $$anonymous$$athf.Tan(properPosition.x/properPosition.y);
         var x = $$anonymous$$athf.Cos(bill);
         var y = $$anonymous$$athf.Sin(bill);
         GUI.DrawTexture(Rect(x - 25,Screen.height - y - 25,50,50),HighObjectiveIcon); // draw the actual icon on the screen
     }
 }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotation Jerks when Copying From Different Object 1 Answer

Realtime Object Rotation on iPad 0 Answers

Smooth rotation in 90° increments 0 Answers

How To Check If X Rotation Is Between Two Numbers?? 1 Answer

space flying system 3 Answers


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