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 williampigmeu · Jul 26, 2012 at 06:29 PM · cameramovementcharactermousesmooth

Smooth Camera Movement script with problem.

Well, I seen an script to make camera move smoothly, but, it makes the character have problems to move, and I don't know why.

Here is the script:

 //Mouse rotation input
 private var rotationX : float = 0;
 private var rotationY : float = 0;
 
 //Mouse look sensitivity
 public var sensitivityX : float = 2;
 public var sensitivityY : float = 2;
 
 //Default mouse sensitivity
 public var defaultSensX : float = 2;
 public var defaultSensY : float = 2;
 
 //Used to calculate the rotation of this object
 private var xQuaternion : Quaternion;
 private var yQuaternion : Quaternion;
 private var originalRotation : Quaternion;
 
 //Minimum angle you can look up
 public var minimumY : float = -60;
 public var maximumY : float = 60;
 
 //Number of frames to be averaged, used for smoothing mouselook
 public var frameCounterX : int = 35;
 public var frameCounterY : int = 35;
 
 //Array of rotations to be averaged
 private var rotArrayX = new Array ();
 private var rotArrayY = new Array ();
 ///////////////////////////////////////////////////////
 
 function Start()
 {
 //Lock/Hide cursor
  Screen.lockCursor = true;
     if (rigidbody) rigidbody.freezeRotation = true;
      originalRotation = transform.localRotation;
 }
 ///////////////////////////////////////////////////////
 
 function Update()
 {
 //Mouse/Camera Movement Smoothing: 
 //Average rotationX for smooth mouselook
  var rotAverageX : float = 0;
  
  rotationX += Input.GetAxis("Mouse X") * sensitivityX;
  
     //Add the current rotation to the array, at the last position
     rotArrayX[rotArrayX.length] = rotationX;
 
     //Reached max number of steps?  Remove the oldest rotation from the array
     if (rotArrayX.length >= frameCounterX) 
     {
         rotArrayX.RemoveAt(0);
     }
 
     //Add all of these rotations together
     for (var i_counterX = 0; i_counterX < rotArrayX.length; i_counterX++) 
     { //Loop through the array
         rotAverageX += rotArrayX[i_counterX];
     }
 
     //Now divide by the number of rotations by the number of elements to get the average
     rotAverageX /= rotArrayX.length;
    
 //Average rotationY, same process as above
  var rotAverageY : float = 0; 
  rotationY += Input.GetAxis("Mouse Y") * sensitivityY; 
     rotArrayY[rotArrayY.length] = rotationY;
     if (rotArrayY.length >= frameCounterY) 
     {
         rotArrayY.RemoveAt(0);
     }
     for (var i_counterY = 0; i_counterY < rotArrayY.length; i_counterY++) 
     {
         rotAverageY += rotArrayY[i_counterY];
     }
     rotAverageY /= rotArrayY.length;
 
 //Set Rotation Limits for vertical    
 //    if ((rotAverageY >= -360) && (rotAverageY <= 360))
 //    {
 //        rotAverageY = Mathf.Clamp (rotAverageY, minimumY, maximumY);
 //    }
 //    else if (rotAverageY < -360)
 //    { 
 //        rotAverageY = Mathf.Clamp (rotAverageY+360, minimumY, maximumY);
 //    }
 //    else
 //    {
 //        rotAverageY = Mathf.Clamp (rotAverageY-360, minimumY, maximumY);
 //    }
 
 //Apply and rotate this object
     xQuaternion = Quaternion.AngleAxis (rotAverageX, Vector3.up);
     yQuaternion = Quaternion.AngleAxis (rotAverageY, Vector3.left);
 
     transform.localRotation = originalRotation * xQuaternion * yQuaternion;
 }
Comment
Add comment · Show 4
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 Piflik · Jul 26, 2012 at 06:38 PM 0
Share

What script do you use for the player's movement?

avatar image williampigmeu · Jul 26, 2012 at 06:46 PM 0
Share

FPS Controller

avatar image Piflik · Jul 26, 2012 at 06:51 PM 0
Share

The FPS Controller already has camera control...I'm not sure, but I think above script is meant for third person...

avatar image SomeGuy22 · Jul 26, 2012 at 07:15 PM 0
Share

Camera scripts should not affect the player's movement, maybe you should post your movement script.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Move camera when mouse is on the edge? 1 Answer

c# scripting navigation problems 1 Answer

Camera Movement issue 1 Answer

character movement follows the direction of camera -1 Answers

change move controls relative to player 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