Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 flore33Me · May 08, 2017 at 08:19 PM · camerarotatearoundclamp

Rotate camera up and down with mouse input with to min and max

I am trying to have a camera rotating around a globe and clamp the top and bottom of the movement. The mouse should move up and down and when it reaches its max and min the globe should stop at that point and if I move my mouse back it move the other way. I have tried many solution but nothing is working. So far the best I have come up by reading many post is this script as it is moving up and down and not stopping when it reaches its min or max but now it is flipping instead.

Could someone help on this issue I cannot figure it out. It has to be from the mouse input that the camera is moving around the globe as it is for a touch screen. I also need the camera moving around the globe not the globe moving. I know how To move the globe and clamp the min and max .

 private Ray ray;
 public GameObject targetItem;
 private Vector3 point;//th cooord to point where the camera look at
 private RaycastHit hit;
 public LayerMask touchInputMask;
 private float angularSpeed = 90;
 private float targetRotationAngle = 45;
 private float currentRotationAngle = -45;
 
 private float rotationX;
 private float rotationY;
 private float Speed = 50;

 // Use this for initialization
 void Start () {

     point = targetItem.transform.position;//get target cooord
 }
   

 // Update is called once per frame
 void Update () 
     {
 
 }

 void FixedUpdate()
 {
     if (Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0))
     {
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hit, touchInputMask))
         {
             GameObject recipient = hit.transform.gameObject;
             rotationX = Input.GetAxis("Mouse X")* Time.deltaTime*5;
             rotationY = Input.GetAxis("Mouse Y")* Time.deltaTime*5;
             if (Input.GetMouseButton(0))
             {
                 if (currentRotationAngle + rotationY > targetRotationAngle)
                 {
                     rotationY = targetRotationAngle - currentRotationAngle;
                     //Stop updating when we are going to reach the target angle.
                     enabled = false;
                 }

                 transform.RotateAround(point, Vector3.right, rotationY*Speed);
                 transform.LookAt(point);//make cam look at it

             }
         }
     }
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Beks_Omega · Jul 06, 2017 at 08:42 PM

Idk if you still need this but for anyone finding this in the future a very lovely person on stackoverflow gave me the answer to this question.

Here's the link to that question:

https://stackoverflow.com/questions/44837086/how-to-limit-clamp-y-axis-rotation-for-transform-rotatearound-unity

And here's a link to the stuff I used from it:

http://answers.unity3d.com/questions/1370422/limit-y-axis-transformrotatearound.html

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

Answer by DarkFang100 · Jul 06, 2017 at 10:13 PM

I'm pretty sure that you can just have Camera.transform.position = Input.GetMousePosition or something like that.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotating and orbiting an game object with a stop angle 0 Answers

Clamp RotateAround is not working on Camera. 1 Answer

Clamping RotateAround 1 Answer

Rotatearaound a moving object 1 Answer

Limit camera rotation with RotateAround 3 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