Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 siddharth3322 · Jan 19, 2016 at 09:47 AM · unity 5camerarotation3drotate

Rotate camera only in 2 directions based on player touch

I want to rotate my camera based on player touch. If player moves his finger on horizontal direction then camera need to rotate on y -axis and player moves his finger on vertical direction then camera need to rotate on x-axis.

I have written this code but don't working as expected, it starts moving in any direction. Seems like can't under our control.

 // Update is called once per frame
     void LateUpdate ()
     {
     
         // If there are two touches on the device...
         if (Input.touchCount == 1) {
             // Store currnet touch.
             Touch touch = Input.GetTouch (0);
 
             Vector3 axis = touch.deltaPosition;
 
             transform.RotateAround (transform.position, axis, 4f);
         }
     }

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 USMANHEART · Jan 04, 2017 at 09:40 AM 0
Share

pitch -= Input.GetTouch(0).deltaPosition.y rotSpeed Time.deltaTime; yaw += Input.GetTouch(0).deltaPosition.x rotSpeed Time.deltaTime;

         // limit for Y
         pitch = $$anonymous$$athf.Clamp(pitch, $$anonymous$$Y, maxY);

         this.transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by USMANHEART · Jan 04, 2017 at 10:11 AM

Simply just use Vector2 instead of Vector3

void LateUpdate () {

      // If there are two touches on the device...
      if (Input.touchCount == 1) {
          // Store currnet touch.
          Touch touch = Input.GetTouch (0);
 
          Vector2 axis = touch.deltaPosition;
 
          transform.RotateAround (transform.position, axis, 4f);
      }
  }
Comment
Add comment · 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

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

51 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 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 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 avatar image avatar image avatar image

Related Questions

player rotate to camera direction but not moving in it's direction 0 Answers

Need help for player rotation and camera rotation 0 Answers

How do i get the Raycast rotation? 1 Answer

Mouse axes based on position, not movement. 1 Answer

How to Reset Quaternion/Rotation On 3D Object After Dragging Mouse? 2 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