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 nar · Feb 08, 2014 at 08:00 AM · camerainputrotatez axismouse-look

how to get mouselook that the mouse X and mouse Y wasn't depend on X and Y axis when i got to rotated in Z axis?

i have this script :

 #pragma strict
      
     var lookSpeed = 3.0;
     var moveSpeed = 1.0;
     var scrollspeed = 100;
      
     private var rotationX = 0.0;
     private var rotationY = 0.0;
     private var rotationZ = 0.0;
      
     function Update ()
     {
     rotationX += Input.GetAxis("Mouse X")*lookSpeed;
     rotationY += Input.GetAxis("Mouse Y")*lookSpeed;
     rotationZ -= Input.GetAxis("Mouse ScrollWheel")*scrollspeed;
   
      
     transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
     transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
     transform.localRotation *= Quaternion.AngleAxis(rotationZ, Vector3.forward);
      
     transform.position += transform.forward*moveSpeed*Input.GetAxis("Vertical");
     transform.position += transform.right*moveSpeed*Input.GetAxis("Horizontal");
     }


i put this script in camera. it for moving and rotate my kamera. that's script was work. but, when have rotate (my camera) in Z axis, mouse X still depend on X axis, and mouse Y still depend on Y axis...

how can i get mouselook that the mouse X and mouse Y wasn't depend on X and Y axis when i got to rotated in Z axis?
(When i have rotate in Z axis, if i take a positif mouse X,it look change like our eyes look at the right side, otherwise too,and if i take positif mouse Y,it look change like our eyes look at the up side, otherwise too)

(i'm sorry if i make a bad grammar in my english)

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 erick_weil · Feb 18, 2014 at 11:56 AM 0
Share

use parents, make a Empty GameObject andd assigs as child your camera, in the empty GameObject make then move towards and rotate in X and Y, and in the camera, only rotate in Z

avatar image nar · Feb 19, 2014 at 06:25 AM 0
Share

i have tried it. but when i have rotate in Z axis, if i take a positif mouse X,it not look change like our eyes look at the right side, and otherwise, in mouse Y too...

avatar image nar · Apr 18, 2014 at 12:22 PM 0
Share

this

i have change my kamera script on my builded project. here:

this use for move : #pragma strict var moveSpeed = 1.0;

 function Update () {
     transform.position += transform.forward*moveSpeed*Input.GetAxis("Vertical");
     transform.position += transform.right*moveSpeed*Input.GetAxis("Horizontal");
 }


this use for rotate z axis :

   #pragma strict
       var scrollspeed = 100;
       private var rotationZ = 0.0;

     function Update () {
     rotationZ -= Input.GetAxis("$$anonymous$$ouse ScrollWheel")*scrollspeed;
     
     transform.localRotation = Quaternion.AngleAxis(rotationZ, Vector3.forward);
     }


this use for xy axis :

 #pragma strict
 
 var lookSpeed = 3.0;
 private var rotationX = 0.0;
 private var rotationY = 0.0;
 
 function Update () {
     rotationX += Input.GetAxis("$$anonymous$$ouse X")*lookSpeed;
     rotationY += Input.GetAxis("$$anonymous$$ouse Y")*lookSpeed;
     
     transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
     transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
 }
avatar image nar · Apr 18, 2014 at 12:27 PM 0
Share

(use DWSA key for movement; in my builded project that i have shared in link above)

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

19 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

Related Questions

how to add force in z direction in input.getmousebuttondown ? 1 Answer

Space Camera Issue. 1 Answer

How to make a mesh into a FirstPerson Character? 2 Answers

Return Camera Rotation Z axis to 0 2 Answers

How to move the player object in the same direction as the input axis, considering the cameras direction? 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