• 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 cregox · Sep 28, 2011 at 05:01 PM · camerarotation

Camera Relative Free Orbit

This was originally illustrated by ***superlol*** but it's still unanswered, as far as I can tell. I've tried and failed.

Take the MouseOrbit script and consider the following:

Unity's Traditional

 var rotation = Quaternion.Euler(y, x, 0);

or

 var rotation = Quaternion.AngleAxis(x, Vector3.up);
 rotation *= Quaternion.AngleAxis(y, Vector3.right);

front rotate top spin instead of rotate

I thought by changing the second way I could get the following result, but that's where I was wrong:

Free Orbit Relative to Camera

 // formula yet to be made

front rotate top rotate

Can you bring us the formula? Does it even exist?

Comment
Add comment · Show 3
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 syclamoth · Sep 28, 2011 at 05:06 PM 0
Share

Doesn't RotateAround work, as in the lovingly crafted link above? I think I have a solution to this lying around, I'll have to have a look.

avatar image syclamoth · Sep 28, 2011 at 05:08 PM 0
Share

What does Quaternion.AngleAxis do for you in this situation? For the picture thing, if you make the axis be the normal of the sphere, does that work? Wait, are we talking about the same thing here?

Sorry let me fix that. You want a camera script that always goes in the direction that you move the mouse, and you don't want it to be locked around a specific 'up' axis. Are there any other constraints here?

avatar image cregox · Sep 28, 2011 at 05:11 PM 0
Share

sup again @syclamoth! yeah, you got the picture. RotateAround = AngleAxis and it ain't working. I hope it does work, but I couldn't figure it out.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by astorga · Oct 26, 2011 at 01:49 PM

To achieve the behavior that you want, instead of doing this:

 x += Input.GetAxis("Mouse X") * xSpeed * distance* 0.02;
 y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
 
 var rotation = Quaternion.Euler(y, x, 0);

You should do this:

 x = Input.GetAxis("Mouse X") * xSpeed * distance* 0.02;
 y = -Input.GetAxis("Mouse Y") * ySpeed * 0.02;
 
 var rotation *= Quaternion.Euler(y, x, 0);

This way, the rotation will be applied directly on quaternion, instead of applying it on euler angles.

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 kifcaliph · Nov 21, 2012 at 11:12 AM 0
Share

how can I change the distance without an error as I want to zoom in & out

avatar image astorga · Nov 21, 2012 at 11:47 AM 0
Share

Have you tried to change the "Distance", "Distance $$anonymous$$in" and "Distance $$anonymous$$ax" values?

avatar image
0

Answer by syclamoth · Sep 28, 2011 at 05:19 PM

My solution to this problem was to use a carefully set-out hierarchy of transforms, each controlling a different part of the camera.

In the middle, there is the 'target' transform. It follows the location of the object to be orbited, but does not follow rotation (since it controls the rotation of the camera).

On the outside, where the actual camera is, is the 'zoom' transform. This is a child of the 'target' transform, and should only move its localPosition (to move towards and away from the centre).

If you like, you can put the camera itself on a third transform (for applying extra effects like screen shaking, etc) but for the purposes of the orbit-cam it is not required.

To rotate the camera, use Transform.rotate (not rotateAround, just rotate) in Space.Local by whatever x and y amounts you need, and the outside camera will move around correctly because of transform parenting!

... I assume you don't need a code sample here?

DISCLAIMER- this is something I made a while back, and I may have forgotten how parts of it worked. If it doesn't quite work out for you, tell me, and I'll try to help fix it.

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 cregox · Sep 28, 2011 at 07:18 PM 0
Share

So you'd have this hierarchy: target -> zoom -> camera and use target.rotation = Quaternion.Euler(y, x, 0)?! I really couldn't make this work. If you meant using target.Rotate(y, x, 0, Space.Self) - because Space.Local doesn't seem to exist - I also couldn't figure it out. I don't need a full sample code, but a working piece of the main part (as I've showed) is very welcomed!

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotation seems to pass through condition checks 1 Answer

How do I set a child object to not rotate if the parent WILL be rotating? 1 Answer

allows users to view 360º content without a VR headset 0 Answers

I need help with TPS controls! 0 Answers

Rotate smoothly to place? 0 Answers


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