Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 awplays49 · Dec 23, 2014 at 09:15 PM · clampmathf.clamp

Camera shaking and barely moving after adding a clamp to x rotation?

 using UnityEngine;
 using System.Collections;
 
 public class CameraController : MonoBehaviour {
 
     public int Sensitivity;
     private float MouseYSet;
 
     void Start () {
         MouseYSet = Input.mousePosition.y;
     }
 
     void Update () {
         transform.localRotation = Quaternion.Euler (Mathf.Clamp (transform.rotation.x, -90, 90), 0, 0);
 
         if (Input.mousePosition.y > MouseYSet)
         {
             transform.Rotate (new Vector3 (-1, 0, 0) * (Input.mousePosition.y - MouseYSet) * Sensitivity * 10 * Time.deltaTime);
             MouseYSet = Input.mousePosition.y;
         }
         if (Input.mousePosition.y < MouseYSet)
         {
             transform.Rotate (new Vector3 (-1, 0, 0) * (Input.mousePosition.y - MouseYSet) * Sensitivity * 10 * Time.deltaTime);
             MouseYSet = Input.mousePosition.y;
         }
     }
 }
 
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
Best Answer

Answer by WillNode · Dec 23, 2014 at 10:48 PM

you are better to use Input.GetAxisRaw() Instead.

replace your Update() function with this:

 float y = 0f;
 void Update(){
     y-=Input.GetAxisRaw ("Mouse Y") * Sensitivity * 10 * Time.deltaTime;
     y=Mathf.Clamp (y, -90, 90);
     transform.rotation = Quaternion.Euler(y, 0, 0);
 }

I didn't test the code. but hope it will help

Comment
Add comment · Show 10 · 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 awplays49 · Dec 23, 2014 at 10:58 PM 0
Share

Ok but what about the clamp?

avatar image WillNode · Dec 23, 2014 at 11:00 PM 0
Share

ow... sorry. didn't see that. i will fix it.

avatar image awplays49 · Dec 23, 2014 at 11:03 PM 0
Share

Thank you :)

avatar image awplays49 · Dec 23, 2014 at 11:16 PM 0
Share

One more question, why do you use the - symbol? Is it because when the mouse is on the right its negative and should be positive? if so, what makes it negative?

avatar image awplays49 · Dec 24, 2014 at 12:17 AM 1
Share

Ohhh okay thank you so much for helping me :)

Show more comments
avatar image
0

Answer by conceptfac · Oct 17, 2020 at 11:01 PM

Still shaking!

Comment
Add comment · Show 1 · 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 Bunny83 · Oct 17, 2020 at 11:17 PM 0
Share

Don't use Time.deltaTime with "$$anonymous$$ouse X" or "$$anonymous$$ouse Y" as those are already delta values. $$anonymous$$ultiplying those by deltaTime will makes it frame rate dependent. This is actually mentioned in the documentation, though not explained very clearly.

If the axis is mapped to the mouse, the value is different and will not be in the range of -1...1. Instead it'll be the current mouse delta multiplied by the axis sensitivity. Typically a positive value means the mouse is moving right/down and a negative value means the mouse is moving left/up.

This is frame-rate independent; you do not need to be concerned about varying frame-rates when using this value.

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

29 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

Related Questions

Such thing as a smooth clamp? 1 Answer

my MainChara shakes when the Mathf.Clamp stops it from going off screen 1 Answer

Camera rotating past clamp 0 Answers

Cant Clamp 1 Answer

How to clamp player to viewport constraints when rotating 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