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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by GoRiLLa · Oct 08, 2013 at 05:32 PM · cameraorbitmatrix

Advanced Orbit Camera Around Target

Hi there!

I'm trying to figure out how I could make a mouse orbit script like they've done here: http://www.byggplanlegger.no/

This movement differs from the standard Mouse Orbit script in that the camera adjusts its position and rotation smoothly even when scrolling directly over the poles, without suddenly flipping the vectors, turning the camera up-side down or clamping/locking the up and down vector.

I've looked all over the unity forums for a solution with no luck.

Please help me in the right direction. Do I need to apply a matrix transformation of some kind or is there a simpler solution for this?

Thanks! :)

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 GoRiLLa · Oct 09, 2013 at 01:55 PM 0
Share

Anyone...? The two answers supplied are not correct.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by robertbu · Oct 08, 2013 at 11:12 PM

Here is a bit of code that mimics the behavior of the orbit script at the link. Attach it to the camera and drag and drop the target game object onto the 'target' variable in the inspector.

 #pragma strict
 
 var target : Transform;
 var dist = 10.0;
 var speed = 1.0;
 
 private var euler = Vector3.zero;
 private var center : Transform;
 
 function Start() {
     // Sets the camera up looking directly forward and looking at the 
     //  object with Vector3.zero rotation
     transform.position = target.transform.position + Vector3.back * dist;
     transform.eulerAngles = euler;
     
     // Place an empty game object at the pivot of the target and make the 
     //   camera a child
     center = new GameObject().transform;
     center.position = target.position;
     transform.parent = center; 
 }
     
 function Update() {
     if (Input.GetMouseButton(0)) {
         euler.x -= Input.GetAxis("Vertical") * speed;
         euler.x = Mathf.Clamp(euler.x, -90.0, 90.0);
         euler.y += Input.GetAxis("Horizontal") * speed;
         center.eulerAngles = euler;
     }
 }
Comment
Add comment · Show 6 · 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 GoRiLLa · Oct 09, 2013 at 10:14 AM 0
Share

Thanks, but this will cause the x-rotation to be locked when passing the poles. So this does not mimic what's in the link.

avatar image robertbu · Oct 09, 2013 at 04:29 PM 0
Share

It is not a perfect match, but with the one in the video also cannot be rolled across the the poles. Once you reach a pole view, the object begins to spin on the local 'y' axis. In addition, with the one in the video, there are many times were the mouse movement is non-intuitive. That is the object rotates the opposite way that it did earlier for the same mouse movement. Play with them side by side. Also you can take out the clamp on line 26 to free the movement, but you'll end up with the same backward movement issues that the link app has.

avatar image GoRiLLa · Oct 09, 2013 at 05:21 PM 0
Share

I don't experience any inverting of the mouse movement. I only experience the object rotating on the y-axis when reaching the poles, which is exactly what I want. :)

avatar image robertbu · Oct 09, 2013 at 11:48 PM 1
Share

With these rotation questions, often the hardest part is figuring out the right behavior. I answer a lot of rotation questions on this list, so I have some background in rotations. Let me tell you what I see when I play with the app at your link.

When I first start the app, I see an angle view of a house. Let me label the long side of of that house facing the user at startup configuration the 'back' and the short side then becomes the 'left'. Click and drag horizontally on the house until the either the 'left' side or the 'right' side is facing the user. Click down again and move the mouse up and down. On my machine the house will only rotate through a slight angle and I cannot rotate it to see the top or bottom. The rotation is locked, which to me is very user unfriendly.

Now refresh the web page to get back to the original configuration. Rotate the house slightly to have the 'back' face the user. Click and drag up and down. It works fine and I believe how the user expects. You can see the 'top' and the 'bottom'. Return to the back-on view, and click and move the mouse horizontally until the the 'front' side is facing the user. Click again and move the mouse up and down. Now the house rotates in the opposite direction. That is when the 'back' of the house is facing the user and you move the mouse up, the house rotates to show the 'bottom' as if you grabbed the house and are rotating it. But when viewing the house from the 'front', the house moves in the opposite direction so the movement attempts to show the roof...and opposite from what the user would expect. It is as if you grabbed hold of the edge of a wheel and pulled up only to have the side grabbed go down.

avatar image GoRiLLa · Oct 10, 2013 at 08:05 AM 0
Share

Thanks for all your input, I really appreciate it. And allthough I honestly agree with you I don't really have a choice since the client I'm doing this for has asked specifically for this kind of camera behaviour. Additionally I would really like to know how to do it like in that link just for the sake of learning. Thanks a lot though.

Show more comments

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

16 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

OnMouseDown on what? Camera Movement Help. 1 Answer

Lock target and orbit it 3 Answers

Reproduce WorldToViewportPoint function 2 Answers

Orbit camer while paused? 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