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 rsuryavanshi007 · Apr 22, 2015 at 04:15 PM · c#camerarotationquaternionclamp

how to clamp y axis with Quaternion.Euler in unity

void Rotate() { Vector3 lastDirectionInGlobal = _camera.ScreenPointToRay(rightFingerLastPoint).direction; Vector3 currentDirectionInGlobal = _camera.ScreenPointToRay(rightFingerCurrentPoint).direction;

     Quaternion rotation = Quaternion.identity;
     rotation.SetFromToRotation(lastDirectionInGlobal, currentDirectionInGlobal);
     
     ownTransform.rotation = ownTransform.rotation * Quaternion.Euler(0, kInverse ? rotation.eulerAngles.y : -rotation.eulerAngles.y, 0);

 

     rotation.SetFromToRotation(    cameraTransform.InverseTransformDirection(lastDirectionInGlobal),
                                cameraTransform.InverseTransformDirection(currentDirectionInGlobal));

     cameraTransform.localRotation = Quaternion.Euler(kInverse ? rotation.eulerAngles.x : -rotation.eulerAngles.x, 0, 0) * cameraTransform.localRotation;
 
     rotation =   Quaternion.Euler(Mathf.Clamp (rotation.eulerAngles.x, -80, 80),Mathf.Clamp (rotation.eulerAngles.y, -80, 80), 0);//using mathclamp for rotation limit on x  &  y

     rightFingerLastPoint = rightFingerCurrentPoint;

     rotation = Quaternion.Euler(cameraTransform.rotation.eulerAngles.x, cameraTransform.rotation.eulerAngles.y, 0);
 
     cameraTransform.rotation = rotation;
 
 }

I have done clamping for x axis (-80,80) degree which is working fine, but y axis showing no clamping on (-80,80) degree . Am i doing something wrong. please help me.

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 Graham-Dunnett ♦♦ · Apr 22, 2015 at 04:16 PM 0
Share

You may want to read up on how to format code in questions.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JoeStrout · Apr 22, 2015 at 05:33 PM

There is way too much code here. The "rotation" variable seems to be used for about six different things. In particular, you're applying clamping when you assign rotation on line 13, but then on line 17 (before you've used that clamp rotation for anything!), you reassign rotation to something completely different, with no clamping.

So, that's why the clamping doesn't work... I can't make out what your code is intended to do, but if you simplify it and remove the pointless lines (like line 13), I think you'll be able to fix it.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Clamp Quaternions Rotation for camera 1 Answer

Trouble with Camera Rotation Math 2 Answers

Edited mouselook script rotation clamp not working 0 Answers

Flip over an object (smooth transition) 3 Answers

how do i take gyro rotation and multiply it? 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