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 /
  • Help Room /
avatar image
0
Question by JasonsFreeTime · Jan 11, 2017 at 01:21 AM · vector3directionfolloworbitcalculation

Looking for help with orbit/follow player script vector math calculations

So basically I have an object, a 3D menu, attach itself to a game object when that object is selected. The camera is a first person camera (actually this is for a HoloLens app), so the player can walk around the object and look at it from any angle and I want the 3D menu to move around the object following the player at a particular distance (toward the player) from the root of the object the menu is attached to. The menu is circular so the player can see the menu options around the edge but still see the object as if looking through a scope. I'm fairly new to Unity and vector math, so I'm having trouble figuring this out the basic calculations that are needed. I am already using a billboard script attached to the circular menu so that it constantly faces the player. I just can't get it to move in orbit like fashion following the player (Camera.main) position at a set distance from the object. Note: The menu will appear when the player clicks on the object, but so that the user doesn't forget to close the menu, it will disappear if the player moves away from the object.

Sorry I don't really have any code. Basically I just have the game object called ObjectOfMenu.

(This is a first every post/request for help. I defiantly need to learn quite a bit about vector math.)

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
0
Best Answer

Answer by Scoutas · Jan 11, 2017 at 03:02 AM

I'll asume the object your menu rotates around is a sphere. It might be little bit more complicated to do, if it is a different object, but we could try and tackle that as well.

First things first - we would need two radius'es. One for the sphere object, one for the menu. Secondly, we need a Vector3 for a direction of where you'd want to put your menu on.

 public class Orbit : MonoBehaviour {
 
     // declare both the sphere object and the menu object
     public GameObject sphere;
     public GameObject menu;
 
     // declare the radius of both objects (basically in this case, the menu would float 0.2 units above the sphere)
     public float sphereRadius = 1f;
     public float menuRadius = 1.2f;
 
     // the direction that we need
     Vector3 dirVector;
 
     void Start(){
 
         // let's make the sphere have the radius that we set
         sphere.transform.localScale = Vector3.one * sphereRadius;
     }
 
     void Update () {
 
         // to get the direction that the menu has to be on the sphere, we need to
         // subtract the sphere objects coordinates, from the camera coordinates
         // and afterwards we normalize that vector (so it has magnitude of 1)

         dirVector = (Camera.main.transform.position - sphere.transform.position).normalized;
 
         // now we set the position of the menu. From the center of the sphere object, we move it by the radius for the menu we described
         // in the direction that we have calculated

         menu.transform.position = sphere.transform.position + dirVector * menuRadius;
     }
 }

alt text

I hope this is all clear enough. Do tell if you need something a little bit different.


help.jpg (34.8 kB)
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 JasonsFreeTime · Jan 11, 2017 at 03:38 AM 0
Share

Well, just before I checked this post, I managed to figure it out on my own and came up with basically what you provided. Only difference is that no, the object isn't a sphere and rather than use a radius, I am just using an offset float. Although I may look into using an invisible sphere if it's not typical for the root to be at the exact center of the object I'm showing the menu for. I'll have to play with that.

 void Update()
 {
 Vector3 direction = (Camera.main.transform.position - ObjectOf$$anonymous$$enu.transform.position).normalized;
 
 this.transform.position = ObjectOf$$anonymous$$enu.transform.position + direction * Offset;
 }

Anyhow, I really appreciate your response and am amazed at how much I have to learn about this stuff! But I'm glad I didn't give up, pleased with the results, and very very thankful for your help kind person!

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

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

Related Questions

How to calculate forward/Up/Right without transform, have only vector3? 0 Answers

Rotate around an object to its direction of velocity (C#) 0 Answers

ClampMagnitude while ignoring a direction 0 Answers

How to make a object move forward when is rotated. 0 Answers

change angle towards direction 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