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 KingKongFu · Dec 04, 2012 at 04:56 PM · rotationcamera movementmouse-look

Stop rotation of camera at certian degree

Ok so here is my third attempt but with no success. right now it just freezes the game after a few seconds and does not look any where just straight up. Is there something I missing with this? I am basing it off the mouse look at script in the standard assets. Here is what I have so far: Thanks for any help with this

 var turnSpeed : float = 15f;
 
 var minX :float = -90;
 var maxX : float = 90;
 
 var minY : float = -90;
 var maxY :float = 90;
 
 var rotationX : float = 0f;
 var rotationY : float = 0f;
 var originalRotation : Quaternion;
 var xQuaternion : Quaternion;
 var yQuaternion : Quaternion;
 
 
 function Start () {
 
 }
 
 function Update () {
     
     
     //rotate the comera
     //this works
     this.transform.RotateAroundLocal(Vector3.up, Input.GetAxisRaw("Vertical") * turnSpeed);
     this.transform.RotateAroundLocal(Vector3.forward, Input.GetAxisRaw("Horizontal") * turnSpeed);
     
     
     if(Input.GetAxis("Vertical"))
     {
         rotationX += Input.GetAxis("Vertical") * turnSpeed;
         rotationX = ClampAngle(rotationX, minX, maxX);
     }
     if(Input.GetAxis("Horizontal"))
     {
         rotationY += Input.GetAxis("Horizontal") * turnSpeed;
         rotationY = ClampAngle(rotationY, minY, maxY);
     }
     
     xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
     yQuaternion = Quaternion.AngleAxis (rotationY, -Vector3.right);
     transform.localRotation = originalRotation * xQuaternion * yQuaternion;
          
      
 }
 
  static function ClampAngle(angle :float, min : float , max :float )
     {
         if (angle < -360F)
             angle += 360F;
         if (angle > 360F)
             angle -= 360F;
         return Mathf.Clamp (angle, min, max);
     }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by konashadow · Dec 05, 2012 at 05:42 PM

You could try making a variable that keeps getting added or subtracted from depending on which way you turn, and only allow the object to keep rotating if the variable is in the allowed range.

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 KingKongFu · Dec 06, 2012 at 03:06 PM 0
Share

how would I keep track of the current rotation value ?

avatar image konashadow · Dec 06, 2012 at 04:48 PM 0
Share

At the end of the function, put (var) += 1. Start the camera at the center of the range you want it to turn, and make it rotate to the point you want it to be. Then check what the value of the variable is (make sure it is public). Then just put an if statement checking whether the variable is at the limit or not.

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

10 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

Related Questions

I was trying to have the camera track the mouse and this happened what is wrong??? 3 Answers

Character Mouse Look on Spine 2 Answers

Can't use camera.main [SOLVED] 1 Answer

Flip over an object (smooth transition) 3 Answers

How do I make it roll same speed, no matter what heights my orbit camera is looking at? 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