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
1
Question by David 25 · Mar 04, 2011 at 06:20 PM · cameraiostouchrotatearoundorbit

Keep camera horizontal with RotateAround

Hello,

I've made a script to rotate the camera around an object with touch-gesture (iOS):

var x = Input.touches[0].deltaPosition.x rotateSpeed Time.deltaTime;

var y = Input.touches[0].deltaPosition.y rotateSpeed Time.deltaTime;

transform.RotateAround (gameObject.Find("Cube").transform.position, camera.transform.right, -y); transform.RotateAround (gameObject.Find("Cube").transform.position, camera.transform.up, x);

The camera rotates around the Cube. When I activate one of the two lines separately they work ok.

With only first line active swiping Up-down, rotates the camera around the cube vertically.

With only the second line active swiping left-right, moves the camera around the cube horizontally.

But if I activate them both the movement is not like expected, the camera doesn't keep level with the horizon.Instead it dolly's around. Basically what I'm after is the movement created with the Unity MouseOrbit.js-script (which is only for mouse-movement). But I can't get it working in combination with my script.

Any suggestions? Is it my combining the 2 movements wrong or do I need to build in some sort of restriction? Any advice is greatly appreciated. David

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

2 Replies

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

Answer by Molix · Mar 05, 2011 at 12:52 PM

The second parameter of RotateAround is the axis of rotation. Make sure that is always vertical, e.g. instead of camera.transform.right and up, just use Vector3.right and Vector3.up. You may need to clamp one of the values to something (-90,90) to prevent weirdness at the top/bottom.

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 David 25 · Mar 05, 2011 at 08:37 PM 0
Share

Thank you for the advice. I'll try it asap.

avatar image
1

Answer by Lypheus · Mar 09, 2013 at 01:04 AM

The above does not work for me, try this if you have the same results:

     // fetch the users mouse motion for this frame
     y = -Input.GetAxis( "Mouse Y" ) * ySpeed;
     x = Input.GetAxis( "Mouse X" ) * ySpeed;
     
     // now adjust cameras rotation around target player based on the mouse x,y movement
     transform.RotateAround( target.position, target.right, y );
     transform.RotateAround( target.position, target.up, x );
     transform.rotation = Quaternion.Euler( transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 0f );
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 unity_7goiPoUnrRyJvQ · Mar 30, 2021 at 04:15 PM 0
Share

this worked, thanks!

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

2 People are following this question.

avatar image avatar image

Related Questions

Move Camera Over Terrain Using Touch Input 2 Answers

Control the camera with a half of the touch screen 0 Answers

Help with camera movement using mobile input 0 Answers

Delta touch trembling 0 Answers

Camera Orbit Rotation Problem 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