Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 whitebozo · Mar 26, 2015 at 11:24 PM · c#unity 5uidragradius

Dragable UI Around the Player Using a Radius

I have a menu based application and I'm wondering how to create a dragable panel(using new UI), that can be dragged off screen but instead of staying on the same axis it rotates around the player. As the main application will be using a head tracking peripheral the player can move his/her head to see the floating panels around them and drag them in this enclosed radius around their head.

I am updating an old application so I've done dragable panels before my question is how to rotate a panel around the camera using a radius, also the UI's local rotation is needs to always be pointing at the player, so the player can see the panels contents when they look at it.

Note my previous build used Mathf.Clamp to clamp the panel within another parent panel

Edit*

I've re-purposed an old camera script for the panels to swivel as the user looks at them it looks quiet nice.

I'm still having issues with maintaining the radius between the panel and the main camera though. My last build has the panels in camera space. The UI panels are no longer subject to a parent panel as that limits the mobility of the panels, and the idea of this application is to have easy to access UIs that rotate around the main camera. There is few problems I have came across.

-The UIs need to be relevant to the main camera as it moves in world space, this is the purpose of camera spce placement.

-The UIs do not need to relevant to the cameras rotation, as the UIs will need to be easily dragged off in any direction and retrieved again by the user looking in that direction and dragging them back in to his/her forward facing direction.

If anyone can please help lead me in the right direction, maybe another similar question, It could even be a basic game object locked to a radius as the new UI system are still Game objects.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Igneom · Jun 15, 2015 at 09:09 AM

I've had some problems understanding what you want to do exactly, and even though your question is a little bit old, you could set the position of the UI to a position that is greater than the distance you want the UI to be, in the direction of the mouse relative to the camera, then clamp the magnitude of the vector to the distance of the radius around the camera.

 using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class DraggableAround : MonoBehaviour, IDragHandler
 {
 
     public void OnDrag(PointerEventData eventData)
     {
 
         // Let's just assume the distance from the camera you want is 5
         float distanceFromCamera = 5;
         
         // This is Necessary so we can discover the direction under the mouse from the camera
         Ray ray = Camera.mainCamera.ScreenPointToRay(eventData.position);
         
         // This gets a point on the same direction of the ray, but greater than the position of the
         // distance from the camera, any number you add works, but adding 1 is enough
         Vector3 greaterPosition = ray.GetPoint(distanceFromCamera + 1);
     
         // Here you clamp the magnitude of the greaterPosition according to the distance from the camera
         // now assume the camera.position values are x = 0, y = 0, z = 94, the greaterPosition will have
         // the values x = 0, y = 0, z = 100, the vector3 returned will have the values x = 0, y = 0, z = 5
         // so we add the camera position back so it can be a vector3 relative to the camera
         Vector3 radiusPosition = camera.position + Vector3.ClampMagnitude(greaterPosition, distanceFromCamera);
     
         // Just assign the UI object the radiusPosition
         transform.position = radiusPosition;
     }
 }

Completely untested, but should work.

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 whitebozo · Jun 22, 2015 at 05:11 PM 0
Share

Thank you for your answer, I have been putting off this project for awhile do to other more important matters. I will post on here again and let you know if this works. It does look very promising thank you again. :)

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

prefabs inside content area not fitting entire width of content area? 0 Answers

[SOLVED] Why is text not appearing? 2 Answers

Please Help Me With My Stamina Bar! 1 Answer

Multiple Cars not working 1 Answer

Problem with jumping in fps game 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