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 /
  • Help Room /
avatar image
0
Question by Dragonic TV · Feb 02, 2016 at 11:29 AM · camerarotationjavascriptmouseclick

Camera Script remove a part.

Hello Unity Members. I found a free script online( i know its bad and might be illegal but thats the only thing i found online).Anyways, it's a camera script that rotates camera around player(target) when you click a mouse button. Left click rotates the camera without rotating the target and Right click rotates the camera and the player. That's my problem. I want the right click to be like left click. To not to change target's rotation. I edited the script but nothing seems to work. I might be very rookie with those camera things. Can someone help me ? Again, i want: when i right click to rotate the camera keep target's rotation the same and not rotate with the camera.

 var target:Transform;                                                   // Target to follow
 var targetHeight = 1.7;                                                 // Vertical offset adjustment
 var distance = 12.0;                                                    // Default Distance
 var offsetFromWall = 0.1;                                               // Bring camera away from any colliding objects
 var maxDistance = 20;                                           // Maximum zoom Distance
 var minDistance = 0.6;                                          // Minimum zoom Distance
 var xSpeed = 200.0;                                                     // Orbit speed (Left/Right)
 var ySpeed = 200.0;                                                     // Orbit speed (Up/Down)
 var yMinLimit = -80;                                                    // Looking up limit
 var yMaxLimit = 80;                                                     // Looking down limit
 var zoomRate = 40;                                                      // Zoom Speed
 var rotationDampening = 3.0;                            // Auto Rotation speed (higher = faster)
 var zoomDampening = 5.0;                                        // Auto Zoom speed (Higher = faster)
 var collisionLayers:LayerMask = -1;             // What the camera will collide with
 var lockToRearOfTarget = false;                         // Lock camera to rear of target
 var allowMouseInputX = true;                            // Allow player to control camera angle on the X axis (Left/Right)
 var allowMouseInputY = true;                            
  
 private var xDeg = 0.0;
 private var yDeg = 0.0;
 private var currentDistance;
 private var desiredDistance;
 private var correctedDistance;
 private var rotateBehind = false;
  
  
 @script AddComponentMenu("Camera-Control/Third Person Camera Orbit (MMORPG Like)")
  
 function Start ()
 {
         var angles:Vector3 = transform.eulerAngles;
         xDeg = angles.x;
         yDeg = angles.y;
         currentDistance = distance;
         desiredDistance = distance;
         correctedDistance = distance;
 
  }
 
 function LateUpdate ()
 {
         if (!target)
                 return;
        
         var vTargetOffset:Vector3;
        
 
         if (GUIUtility.hotControl == 0)
         {
                         if (allowMouseInputX)
                                 xDeg += Input.GetAxis ("Mouse X") * xSpeed * 0.02;
 
                         if (allowMouseInputY)
                                 yDeg -= Input.GetAxis ("Mouse Y") * ySpeed * 0.02;   
         }
         yDeg = ClampAngle (yDeg, yMinLimit, yMaxLimit);
 
         var rotation:Quaternion = Quaternion.Euler (yDeg, xDeg, 0);
 
         desiredDistance -= Input.GetAxis ("Mouse ScrollWheel") * Time.deltaTime * zoomRate * Mathf.Abs (desiredDistance);
         desiredDistance = Mathf.Clamp (desiredDistance, minDistance, maxDistance);
         correctedDistance = desiredDistance;
 
         vTargetOffset = Vector3 (0, -targetHeight, 0);
         var position:Vector3 = target.position - (rotation * Vector3.forward * desiredDistance + vTargetOffset);
  
         var collisionHit:RaycastHit;
         var trueTargetPosition:Vector3 = Vector3 (target.position.x, target.position.y + targetHeight, target.position.z);
  
         var isCorrected = false;
         if (Physics.Linecast (trueTargetPosition, position, collisionHit, collisionLayers))
         {
                 correctedDistance = Vector3.Distance (trueTargetPosition, collisionHit.point) - offsetFromWall;
                 isCorrected = true;
         }
  
         currentDistance = !isCorrected || correctedDistance > currentDistance ? Mathf.Lerp (currentDistance, correctedDistance, Time.deltaTime * zoomDampening) : correctedDistance;
 
         currentDistance = Mathf.Clamp (currentDistance, minDistance, maxDistance);
 
         position = target.position - (rotation * Vector3.forward * currentDistance + vTargetOffset);
    
         transform.rotation = rotation;
         transform.position = position;
 }
  
 function RotateBehindTarget()
 {
 }
  
  
 static function ClampAngle (angle : float, min : float, max : float)
 {
    if (angle < -360){
       angle += 360;
       Debug.Log(angle);  }
    if (angle > 360)
       angle -= 360;
    return Mathf.Clamp (angle, min, max);
 }
 

Thanks alot!

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

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

Related Questions

How do you disallow an angle from going to a certain range while rotating? 0 Answers

How to rotate camera view? 0 Answers

Rotate Camera only Horizontal? 1 Answer

Tips on how to assign with Vuforia AR SDK main.camera to render at 90 degrees to object target? Augmented Reality 0 Answers

Roll a ball, treating where the camera is rotating as forward? 0 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