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 Solid_Metal · Mar 30, 2015 at 09:28 AM · androidmobiletouchrotate objectfix

Fix Rotate Object with touchscreen on X and Y axis

guys, i need a little bit help, already done googling but still not found any solution so i want to rotate my object with a touch input, heres the code

target.transform.Rotate(touchDeltaPosition.x 3.0f,touchDeltaPosition.y 3.0f ,0,Space.World);

it works perfectly, but the problem is it rotate diagonally, i need it to fix rotate only on x and y axis, i already done quite lot of validation and solution i found on this forum and stackoverflow, but still nothing

heres a simple drawn i made to made it a little bit more clear http://i.imgur.com/cAeg8yr.png what i need is the object to rotate fix on X and Y axis (the green line) , but unfortunately with my script, it'll also rotate horizontally (the red line) and i don't want it

i'm using unity 5

thank you in advance

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 flashframe · Mar 30, 2015 at 06:44 PM 1
Share

If you mean you don't want to rotate in Z, you could add another line of code after your touch code that limits the z-axis to 0.

 target.transform.rotation = Quaternion.Euler(target.transform.rotation.EulerAngles.x, target.transform.rotation.eulerAngles.y, 0);

But if you are rotating freely on the X and Y axis, then there's going to be diagonal movement, unless you limit it to one axis at a time. (If you rotate something left and up at the same time, then it is rotating diagonally, correct?).

avatar image Solid_Metal · Mar 30, 2015 at 09:12 PM 0
Share

indeed, i already try write validation for that, but unfortunately it still not working correctly, could you see what is going wrong?

 if(!vertical && !horizontal)
                 {
                     float swipeDistVertical = (new Vector3(0, touchDeltaPosition.y, 0) - new Vector3(0, startPos.y, 0)).magnitude;              
                     if (swipeDistVertical > 0)                  
                     {                   
                         float swipeValue = $$anonymous$$athf.Sign(touchDeltaPosition.y - startPos.y);                   
                         if (swipeValue > 0 || swipeValue < 0)//up swipe     
                         {
                             vertical = true;
                             horizontal = false;
                         }                               
                     }               
                     float swipeDistHorizontal = (new Vector3(touchDeltaPosition.x,0, 0) - new Vector3(startPos.x, 0, 0)).magnitude;             
                     if (swipeDistHorizontal > 0)                    
                     {                   
                         float swipeValue = $$anonymous$$athf.Sign(touchDeltaPosition.x - startPos.x);                   
                         if (swipeValue > 0 || swipeValue < 0)//right swipe
                         {
                             horizontal = true;
                             vertical = false;
                         }                           
                     }
                 }
     
                 if(vertical)
                 {
                     target.transform.Rotate(touchDeltaPosition.y * 3.0f, 0,0,Space.World);
                 }
                 if(horizontal)
                 {
                     target.transform.Rotate(0,touchDeltaPosition.x * 3.0f,0,Space.World);
                 }
     }

The vertical and horizontal booleans are set to false when the touch begins.

avatar image flashframe · Mar 30, 2015 at 10:39 PM 0
Share

Just to be clear, are you trying to limit the rotation to either y-axis or x-axis depending on whether you swipe up/own or left/right?

avatar image Solid_Metal · Mar 31, 2015 at 12:29 AM 0
Share

yeah, not exactly swipe tho, but drag the touch input, that's why i use delta position ins$$anonymous$$d touch ended phase

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Touch Input positions are different on iOS and Android? 2 Answers

Raycast from player to touch point? 2 Answers

Android double jump not working correctly 1 Answer

Avoid touch input when pressing the "Pause" button 1 Answer

Mobile FPC in unity 5 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