• 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 aminasadi · Jun 13, 2016 at 12:42 PM · unity 5camerarotationvectrosity

Align the Camera to the head of the drawn lines in vectorsity

Hi,

I'm using Vectrosity to draw3D continues lines on a flat surface (x,y). Imagine I'm drawing a path or graph on the screen out of a list of random vector3 points. I like to have the camera move with the head of the line and a little bit tilted so the head and portion of the last line can be seen as the line continue to be drawn exactly like a navigation software that shows the path. Further, I can't use auto follow or smooth follow scripts as the transform of the object belongs to the whole graph object and not only the last line of the drawn lines.

Right now I can move the camera on top of the headPos of the line but I can't figure out how to rotate the camera so the line always be towards up (e.g. like a navigation application). The current solution rotate the camera sometimes correctly but sometimes 180 degrees incorrect.

 Vector3 headPos = myLine.points3[myLine.points3.Count - 1];
 Vector3 beforeHeadPos = myLine.points3[myLine.points3.Count - 2];
 Vector3 camPos = Vector3.Lerp(beforeHeadPos, headPos, 1.0f); ;
 camPos.z = -600;
 mainCam.transform.position = camPos;
             
 Debug.Log(angleBetween(beforeHeadPos, headPos));
 
 //ROTATION ISSUE
 mainCam.transform.rotation = Quaternion.Euler(0, 0, 90 + angleBetween(beforeHeadPos, headPos));

 float angleBetween(Vector3 v1, Vector3 v2) {
     return Mathf.Atan((v2.y - v1.y) / (v2.x - v1.x)) * 180 / Mathf.PI;
     //return (angle < 0 ? angle+360 : angle);
 }

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 aminasadi · Jun 13, 2016 at 08:12 AM 0
Share

ok I think I found a workaround! But please comment on my code anyway especially how can I title the camera a bit. The camera rotation jitters between 90 degrees (upward) and 180 degree (downward) for some reason. This can be fixed by adding 0.01 degree to the result of angleBetween. I also swap the parameters to the function. Further I replaced Eureler with AngleAxis. That doesn't change anything.

 mainCam.transform.rotation = Quaternion.AngleAxis(91 + angleBetween(headPos,  beforeHeadPos), new Vector3(0,0,1));

 float angleBetween(Vector3 v1, Vector3 v2) {
         float angle = $$anonymous$$athf.Atan2((v2.y - v1.y), (v2.x - v1.x)) * 180 / $$anonymous$$athf.PI;
         return (angle < 0 ? angle+360 : angle);
 }

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotating Player with Mouse 0 Answers

Can't do Quaternion.AngleAxis twice. 1 Answer

How can I turn the direction of bicycle in Unity? 3 Answers

how do i make first person character rotate left and right along with camera? 0 Answers

Virtual Reality - Android Gyroscopic Camera - Pitch and Roll Issues. 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