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 Sheepvsmonkey · Oct 27, 2014 at 04:45 PM · c#quaternionclamp

Clamping the camera X axis when not using the mouse axis? C#

I have a project which involves using a 'deadzone'/'free aiming' I'm a novice with C# and finally from going over forums found a way of doing it, it might not be the best way but i was happy it worked. The only problem is that i have been really struggling to clamp the rotation of the camera. I have given it many attempts and got quite close when using euler angles but had the problem of only on side of the clamp working and the other making the value jump to 0. I understand roughly what a quaternion is but have been struggling to make it work in code especially when your not supposed to change the value of just one of the x,y,z,w. Here is the code i have been using

     public float noTurn = 0.1f; // Extent of the no-turn zone as a fraction of Screen.height;
     public float factor = 150.0f;
     private Vector3 center;
     public bool YActive;
     public bool XActive;
 
     public float maxX;
     public float minX;
     /*private Vector3 maximumXRotation;
     private Vector3 minimumXRotation;
     private Vector3 XRotation;*/
 
 
 
     // Use this for initialization
     void Start ()
     { 
         center = new Vector3(Screen.width / 2, Screen.height / 2, 0);
 
         /*maximumXRotation = new Vector3 (maxX, 0f, 0f);
         minimumXRotation = new Vector3 (minX, 0f, 0f);
         XRotation = new Vector3 (transform.localEulerAngles.x, 0f, 0f);*/
 
     }
     
     void Update () 
     {
         Vector3 delta = (Input.mousePosition - center) / Screen.height;
         Debug.Log(delta);
 
 
 
         if (delta.y > noTurn && YActive == true) 
             transform.Rotate(-(delta.y - noTurn) * Time.deltaTime * factor, 0f, 0f);
         if (delta.y < -noTurn && YActive == true)
             transform.Rotate(-(delta.y + noTurn) * Time.deltaTime * factor, 0f, 0f);
         if (delta.x > noTurn && XActive == true)
             transform.Rotate(0f, (delta.x - noTurn) * Time.deltaTime * factor, 0f);
         if (delta.x < -noTurn && XActive == true)
             transform.Rotate(0f, (delta.x + noTurn) * Time.deltaTime * factor, 0f); 
     
         /*if (YActive == true)
                         Mathf.Clamp (transform.localEulerAngles, minimumXRotation, maximumXRotation);*/
         /*if (YActive == true){
             LateUpdate()}*/
 
     }
 
     
     /*void LateUpdate() 
     { 
         transform.localEulerAngles = new Vector3( Mathf.Clamp(transform.rotation.eulerAngles.x, minX, maxX), transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z ); 
     }*/


There are a few attempts in there which are all withing the different / /. Was hoping someone could point me in the right direction or maybe a better solution to the free aiming which might make it easier to solve the clamping problem.

Thanks.

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

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

2 People are following this question.

avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Clamping the camera X axis when not using the mouse axis? C# 0 Answers

Multiple Cars not working 1 Answer

Clamp Quaternions Rotation for camera 1 Answer

how to clamp y axis with Quaternion.Euler in unity 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