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 slayer29179 · Oct 06, 2011 at 06:26 PM · camerajavascriptmouse-look

Converted MouseLook from C# to Java problems

Hey, sorry to keep posting but :/ problem and this one has struck me big time, it works perfect looking up and down but i cannot look left or right so that also stops diagonal :/ i used this code http://www.unifycommunity.com/wiki/index.php?title=MouseLookPlus and change it because they said we could in the notes but help this is my code thank you in advance to whoever fixes it

 enum Axes {MouseXandY, MouseX, MouseY}
 var Axis : Axes = Axes.MouseXandY;

 var sensitivityX = 15.0;
 var sensitivityY = 15.0;

 var rotationX = 0.0;
 var rotationY = 0.0;

 function Update ()
 {
     if (Axis == Axes.MouseXandY)
     {
         // Read the mouse input axis
         rotationX += Input.GetAxis("Mouse X") * sensitivityX;
         rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
     }
     else if (Axis == Axes.MouseX)
     {
         // Read the mouse input axis
         rotationX -= Input.GetAxis("Mouse X") * sensitivityX;
     }
     else if (Axis == Axes.MouseY)
     {
         // Read the mouse input axis
         rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
     }
 }

please help it looks like it should work to me because they are both the same as y except has changed please help thank you

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
3
Best Answer

Answer by aldonaletto · Oct 07, 2011 at 12:00 AM

There's one instruction missing - just the most important, the last one in Update:

        ...
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
    }
    // this instruction was missing:
    transform.localEulerAngles = Vector3(rotationY, rotationX, 0);
}
With this instruction, this MouseLook works perfectly in all modes. Try it and let me know if you still have problems.
Comment
Add comment · Show 3 · 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 slayer29179 · Oct 07, 2011 at 09:55 PM 0
Share

thanks for trying but it gives me an error : "It is not possible to invoke an expression of type 'UnityEngine.Vector3'." but i don't know if it will help or not but i added this code based on yours - transform.localRotation = Quaternion.AngleAxis (rotationX,Vector3.up); transform.localRotation *= Quaternion.AngleAxis (rotationY,Vector3.left); now the x axis works but the y doesn't

avatar image aldonaletto · Oct 10, 2011 at 02:23 PM 0
Share

Forgive me, I wrote the wrong thing: localEulerAngles is a property, not a function. I fixed the answer.

avatar image slayer29179 · Oct 10, 2011 at 08:50 PM 0
Share

thank you very much :) you have been most kind, it now works :) thank you again

avatar image
0

Answer by jpeg · Jan 14, 2012 at 01:16 AM

hate to bust in here but you forgot to limit the rotation. (please note that this is reference to anyone else who may be looking for this later on

enum Axes {MouseXandY, MouseX, MouseY} var Axis : Axes = Axes.MouseXandY;

var sensitivityX = 15.0; var sensitivityY = 15.0;

var rotationX = 0.0; var rotationY = 0.0;

var minimumY :float = -60F; var maximumY :float = 60F;

var minimumX :float = -360F; var maximumX :float = 360F;

function Update () { if (Axis == Axes.MouseXandY) { // Read the mouse input axis rotationX += Input.GetAxis("Mouse X") -sensitivityX; rotationY += Input.GetAxis("Mouse Y") -sensitivityY; } else if (Axis == Axes.MouseX) { // Read the mouse input axis rotationX -= Input.GetAxis("Mouse X") -sensitivityX; //rotationX = Mathf.Clamp (rotationX, minimumX, maximumX); } else if (Axis == Axes.MouseY) { // Read the mouse input axis rotationY += Input.GetAxis("Mouse Y") -sensitivityY; rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); } transform.localEulerAngles = Vector3(rotationY, rotationX, 0); }

I annotated the limit x because I had no need for it in my code

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 aldonaletto · Jan 14, 2012 at 01:25 AM 0
Share

Good point: the vertical excursion must be limited - if it reaches or passes 90 degrees the camera gets completely crazy.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to change main camera and access to the other scripts?? 0 Answers

Making an object move with the camera 1 Answer

Camera movement in a 2D? (like angry birds) 1 Answer

Super mario Camera Script 0 Answers

How to change overlay with timer? 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