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 ZaxOnTheBeach · May 25, 2013 at 12:15 AM · camerarotationrotatefixedupdate

Camera 'FixedUpdate' and Rotate function problem

Hey everyone, I have a 3rd person camera script with a rotate function that allows me to rotate around my character on a 90 degree at-a-time basis and stop. However I noticed that the Updates between my character movement and my camera were clashing poorly so I changed the LateUpdate for my camera functions to FixedUpdate which solved that problem. But now when I use my Rotate function in the game when the rotation is complete I noticed the camera wigs out for a split second. (Only when my character is moving! When the character is still this doesn't occur)

Here is the script;

 #pragma strict
 
 
 
 
 
 
 var rotationSpeed : float = 5.0;
 var rotateTime : float = 3.0;
 private var rotateDegrees : float = 90.0;
 private var rotating : boolean = false; 
 // Player
 var target : Transform;
 var distance = 10.0;
 var zoomSpeed = 10.0;
 public var height = 5.0;
 var heightDamping = 2.0;
 
 //Zooming Parimeters
 var maxZoomOut = 25.0;
 private var maxIn = 5.0;
 
 
 //UNUSED
 private var rotationDamping = 3.0;
 
 
 // Place the script in the Camera-Control group in the component menu
 
 @script AddComponentMenu("Camera-Control/Smooth Follow")
 
 function LateUpdate () {
     // Early out if we don't have a target
     if (!target)
         return;
     
     // Calculate the current rotation angles
     var wantedRotationAngle = target.eulerAngles.y;
     var wantedHeight = target.position.y + height;
         
     var currentRotationAngle = transform.eulerAngles.y;
     var currentHeight = transform.position.y;
     
     // Damp the rotation around the y-axis
     
 
     // Damp the height
     currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
 
     // Convert the angle into a rotation
     var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
     
     
 
     transform.position = target.position;
     transform.position -= currentRotation * Vector3.forward * distance;
 
     // Set the height of the camera
     transform.position.y = currentHeight;
     
     // Always look at the target
     transform.LookAt (target);
     
     //Controls for zooming the camera    
     distance = distance -= Input.GetAxis("RightStickY") * Time.deltaTime * zoomSpeed;
     distance = Mathf.Clamp(distance,maxIn,maxZoomOut);
 
         if (Input.GetAxis("RightStickX") == 1) {
             
              Rotate(transform,target,Vector3.up,rotateDegrees,rotateTime);
         }    
     if (Input.GetAxis("RightStickX") == -1) {
         
         Rotate(transform,target,-Vector3.up,rotateDegrees,rotateTime);
     }
         
 
                 
                                 
                                                             
 }
 
 
   
 
 function Rotate (thisTransform : Transform, target : Transform, rotateAxis : Vector3, degrees : float, totalTime : float) {
 
     if (rotating) return;
 
     rotating = true;
 
    
 
     var startRotation = thisTransform.rotation;
 
     var startPosition = thisTransform.position;
 
     transform.RotateAround(target.position, rotateAxis, degrees);
 
     var endRotation = thisTransform.rotation;
 
     var endPosition = thisTransform.position;
 
     thisTransform.rotation = startRotation;
 
     thisTransform.position = startPosition;
 
    
 
     var rate = degrees/totalTime * rotationSpeed;
 
     for (var i = 0.0; i < degrees; i += Time.deltaTime * rate) {
 
         yield;
 
         thisTransform.RotateAround(target.position, rotateAxis, Time.deltaTime * rate);
 
     }
 
  
 
     thisTransform.rotation = endRotation;
 
     thisTransform.position = endPosition;
 
     rotating = false;
 
 }
 

Any help would be greatly appreciated!!

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

14 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

Related Questions

How to restrict rotation properly 2 Answers

Float the camera back to his position 1 Answer

How to rotate my camera? 2 Answers

Movement with camera and rotation of objects 1 Answer

My character suddenly stopped looking up/down 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