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 NikEy · Oct 27, 2012 at 11:51 PM · camerarotationcontrol

MouseOrbit script in alternate space

Unhappy with my previous results I am now using the MouseOrbit script from the wiki.

Unfortunately my environment differs a bit from the assumptions in the script, in that the view is always from the top (e.g. Z = -50) on the X/Y grid (RTS style). The script assumes that one is operating in an environment where one is looking towards Z.

I don't know why but for the love of Christ I cannot adapt the script to work in my alternate space... it doesn't seem to be as simple to just change the axes - the rotations are all screwed up... any ideas?

Here the script:

             x += Input.GetAxis("Mouse X") * 10f * distance * 0.02f;
             y -= Input.GetAxis("Mouse Y") * 10f * 0.02f;
      
             y = ClampAngle(y, yMinLimit, yMaxLimit);
             
             Quaternion rotation = Quaternion.Euler(y, x, 0);
      
             distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * 5, distanceMin, distanceMax);
      
             Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
             Vector3 position = rotation * negDistance + target.transform.position;
      
             transform.rotation = rotation;
             transform.position = position;





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

Answer by Bunny83 · Oct 28, 2012 at 12:01 AM

Well, Unity's usual space is like this. It uses a left-handed system where +z is forward +x is right and +y is up. You're of course not bound to this, but it simplifies a lot when you stick to this system. So for an rts game you would use the x-z plane as ground.

However, it your game is already setup with x-y as ground and -z as up (+z down), you can juse change:

 transform.rotation = rotation;

to

 transform.localRotation = rotation;

and parent this object to an empty gameobject which is rotated downwards (x rotation == 90/-90).

Comment
Add comment · Show 2 · 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 NikEy · Oct 28, 2012 at 02:24 AM 0
Share

Hey thanks for this, but I tried a couple of different ways around this and I couldn't find a way to make it work. It does work however, if the object is at Vector3.zero, but that is not likely to be the case in a non-staged environment. I created a test project that recreates this exact case. If possible, could you kindly have a look at it? http://dl.dropbox.com/u/4674785/Test.zip

Scene 1 is the default case, where you can see that everything works nicely. Scene 2 is my case with axes switched and the camera attached to a rotated empty object. As soon as the target object is not at Vector3.zero anymore, the whole script ceases to work... any idea what I did wrong?

avatar image NikEy · Oct 28, 2012 at 05:56 PM 0
Share

...anyone? I'm really stuck here =/

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

10 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Why the control with gyroscope inverted when I make 180 degrees turn? 1 Answer

Help with camera coding - Modern Zelda-style camera 1 Answer

Keyboard Controlled Overhead Camera Rotation 0 Answers

Very weird rotation axis bug 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