• 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 TargonStudios · Aug 26, 2015 at 03:08 AM · javascriptmouselookrelative

Edit mouse look script to not be effected by rotation

Hello! Currently, I have found and am using a smooth, javascript MouseLook script which I will show below. Right now, the problem I am facing is trying to get the script to act normally no matter what the current rotation is. Here is the script:

 var LookSensitivity : float = 5;
 private var YRotation : float;
 private var XRotation : float;
 private var CurrentYRotation : float;
 private var CurrentXRotation : float;
 private var YRotationV : float;
 private var XRotationV : float;
 var SmoothDamper : float = 0.1;
 
 function Update(){
 YRotation += Input.GetAxis("Mouse X") * LookSensitivity;
 XRotation -= Input.GetAxis("Mouse Y") * LookSensitivity;
 
 XRotation = Mathf.Clamp(XRotation, -90, 90);
 
 CurrentXRotation = Mathf.SmoothDamp(CurrentXRotation, XRotation, XRotationV, SmoothDamper);
 CurrentYRotation = Mathf.SmoothDamp(CurrentYRotation, YRotation, YRotationV, SmoothDamper);
 
 transform.rotation = Quaternion.Euler(CurrentXRotation, CurrentYRotation, 0);
 
 }

Don't get me wrong, the script works perfectly for its intentions, but right now, my player is able to walk around a round planet, but the script doesn't really co-operate with that, since the script works globally, and not relatively. For example, I would want this script to work if the player was upside down, rightside up, ect.. I hope you understand what I mean, what would be the best/easiest fix for my problem?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Craftnime · Aug 26, 2015 at 09:58 PM

Couldn't you place your camera with it's script attached as a child of an empty object, then change the parent right upside down or whatever, in which the camera as a child is in?

Comment
Add comment · Show 2 · 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 TargonStudios · Aug 26, 2015 at 10:25 PM 0
Share

I actually ended up finally fixing it, wasn't as simple as that for me. Thanks for your response though!

avatar image tommyzat TargonStudios · May 17, 2016 at 10:11 AM 0
Share

Could you please share how you fixed it?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

28 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

Related Questions

How to Disable Mouse and Character movement? (Javascript) 1 Answer

Main Camera = false problems 1 Answer

fps MouseLook with animation applied to camera. 1 Answer

Mouse look script help 1 Answer

Instantiate a prefab with a key press to a relative location? 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