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 a.sidd · Mar 20, 2015 at 07:50 PM · c#camerarotationtouch

How stop Z value being effected when rotating X and Y only (C Sharp)?

Hi Everyone,

I'm trying to rotate camera(X and Y only), but Z value is also being effected. Here's the script that I'm using.

 if(Input.touchCount > 0){
 
    my_Touch = Input.GetTouch(0);
 
    if(Input.GetTouch(0).phase == TouchPhase.Moved){
    
     Camera.main.transform.Rotate(my_Touch.deltaPosition.y * rotationSpeed, my_Touch.deltaPosition.x * rotationSpeed,0);
    }
 }

I also tried this but didn't work : http://answers.unity3d.com/questions/30233/problem-with-z-rotation-when-rotating-x-and-y-and.html

Comment
Add comment · Show 4
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 immersiveGamer · Mar 20, 2015 at 09:01 PM 0
Share

Could it be a problem with local and world space? What I am thinking is that you are correctly rotating it but if it is in the wrong space you will also rotate the other space Z axis.

avatar image jpthek9 · Mar 20, 2015 at 09:07 PM 0
Share

@immersiveGamer What does this even mean?

avatar image immersiveGamer · Mar 20, 2015 at 09:19 PM 0
Share

transform.Rotate() rotates an object in local space if you don't define it. You can add an extra argument to rotate in world space if you want. If the Camera is a child of an object and that object is rotated (or gimbal lock happens like in the link you gave) and then you try rotate it like you have it will rotate relative to the object ins$$anonymous$$d of the world space. So try doing

 transform.Rotate(myRotation, Space.World);

avatar image a.sidd · Mar 21, 2015 at 07:23 AM 0
Share

I tried it, but it didn't work. I also tried to put X rotation script to camera and Y rotation script to it's parent, but as I said Z also being effected.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by jpthek9 · Mar 20, 2015 at 08:00 PM

You shouldn't use Unity's transform methods for specific behaviors like this. Instead, create a Vector3 representing a euler rotation and change it manually. Then you can do transform.rotation = Quaternion.Euler(EulerRotation).

Edit: Nevermind. transform.Rotate should work fine for your desires. Your code's correct but are you sure the Z axis is the one you don't want to rotate on?

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 a.sidd · Mar 21, 2015 at 07:34 AM 0
Share

Hi, apologize for late reply. Yes, I don't want to rotate Z axis. In my game, user can rotate and look around the world. So if Z axis got rotated then it would be hard for user to get back it default rotation.

avatar image jpthek9 · Mar 21, 2015 at 04:58 PM 0
Share

Try playing with the rotation values yourself to see which axis rotates what. What I'm saying is that your code is correct and your Z axis rotations shouldn't at all be modified so maybe you're not defining your wanted results correctly.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

touch input speed to camera rotate speed. scaling function needed 0 Answers

Touch Controlled Camera Inertia 1 Answer

How to smoothly rotate camera around an object with touch 1 Answer

Unity input to rotate camera 0 Answers

Touch mouseorbit 5 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