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 static_cast · Oct 18, 2013 at 07:25 PM · mousewalkingz-axis

Mouse Look from scratch rotating Z axis

I wrote a script to use the mouse to look around, but I'm having trouble, because it is rotating the z axis.

 #pragma strict
 var mouseSpeed = 0.1;
 
 function Update()
  {
  //if(rigidbody)
  // rigidbody.freezeRotation = true;
  Screen.lockCursor = true;
 
  var x : float = mouseSpeed * Input.GetAxis("Mouse X");
  var y : float = mouseSpeed * Input.GetAxis("Mouse Y");
 
  transform.Rotate(-y, x, 0.0);
  }

You'll see that I commented out rigidbody.freezeRotation because it didn't work, nor did simply using "transform.rotation.z = 0;".

Here are some details about my program: Capsule [Rigidbody, has movement script]

Main Camera [has mouse look script]

Plane [As a platform] Cube [As an object to jump on] Thanks in advance!
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

Answer by rutter · Oct 18, 2013 at 07:45 PM

When your object rotates around its X axis, its local Y axis changes. If you want to rotate around the world axes, [you can specify that]((http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html)):

 transform.Rotate(-y, x, 0.0, Space.World);
Comment
Add comment · Show 4 · 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 static_cast · Oct 18, 2013 at 11:51 PM 0
Share

Um, it didn't work. :/

avatar image sdgd · Oct 18, 2013 at 11:54 PM 0
Share

what about:

 transform.eulerAngles = new Vector3 (x, y, 0);

you might need to change x for y and y for x

AND OFC!!! :

 var x : float += mouseSpeed * Input.GetAxis("$$anonymous$$ouse X");
 var y : float += mouseSpeed * Input.GetAxis("$$anonymous$$ouse Y");

without that it'll rotate you only for 1°

avatar image suark · Mar 08, 2014 at 07:37 PM 0
Share

Hey, I'm having the same problem and these solutions didn't work :/. Any updates?

avatar image No_Username_Found · Apr 16, 2014 at 04:35 PM 0
Share

This worked for me. However, I only locked the Y axis to Space.World, and kept the X axis local. If they are both locked the problem persisted. Here is what my code looked like: if(Input.GetAxis("$$anonymous$$ouse Y")!=0){

                 transform.Rotate(-Input.GetAxis ("$$anonymous$$ouse Y")*turnSpeed, 0, 0, Space.World);
             }

if(Input.GetAxis("$$anonymous$$ouse X")!=0){

                 transform.Rotate(0, Input.GetAxis("$$anonymous$$ouse X")*turnSpeed, 0);
             }

avatar image
0

Answer by static_cast · Oct 28, 2013 at 09:54 PM

  void Update()
   {
   //We wanna make sure our cursor is locked
   if(Screen.lockCursor == false)
    Screen.lockCursor = true;
 
   //Weird Calculationz
   yRotation -= Input.GetAxis("Mouse Y") * rotationSpeed * Time.deltaTime;
   yRotation = Mathf.Clamp(yRotation, -80, 80);
   xRotation += Input.GetAxis("Mouse X") * rotationSpeed * Time.deltaTime;
   xRotation = xRotation % 360;
 
   //Rotate camera up+down, player left+right
   transform.localEulerAngles = new Vector3(yRotation, 0, 0);
   player.transform.localEulerAngles = new Vector3(0, xRotation, 0);
   }

This is my new code.

Comment
Add comment · 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

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

18 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

Related Questions

MouseOver Doesn't work ON trigger 3 Answers

Is it a bug? 1 Answer

Alt+Tab pointer problem 0 Answers

Mouse Movement on z-axis 0 Answers

Mac version mouse lock not working properly 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