• 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 Eeppi · Feb 02, 2013 at 01:34 PM · camerarotationmouselook

Mouselook 90° Z-angle

I have to rotate my camera 90 degrees and be able to look with mouse. I got it working with 180° angle, but not 90°.

http://dl.dropbox.com/u/70186988/Problem.html <-- Unity webplayer

You can probably see what is problem if you try that demo.

Code:

RotationZ is 90° on those scripts. (Applied on another script)

Script1 (This is attached to camera):

 function Update(){
 Limiter(); //This is just for limiting angle, don't mind about this
 rotationX = script2.rotationX;
 rotationY += Input.GetAxis("Mouse Y") * sensitivity;
 rotAngle = Quaternion.Euler(Vector3(rotationX,rotationY,rotationZ));
 transform.rotation = rotAngle;
 }

Script2 (This is attached to player model):

 function Update(){
 Limiter(); //Still just limiting.
 rotationX += Input.GetAxis("Mouse X") * sensitivity; 
 rotAngle = Quaternion.Euler(Vector3(rotationX,90,rotationZ));
 transform.rotation = rotAngle;
 
 }

I can give you more information if u need. I have been thinking this problem for a while and can't understand what is wrong.


EDIT:

alt text

alt text

Click attachments to see bigger picture. Playerrota = script2, you don't probably need moving script information but it came with screenshots. Mouselook = script1.

pic1b.jpg (59.7 kB)
pic2b.jpg (65.4 kB)
Comment
Add comment · Show 6
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 Wolfram · Feb 03, 2013 at 04:34 PM 0
Share

Can you stop bumping this question please?

avatar image Wolfram · Feb 03, 2013 at 07:18 PM 1
Share

Show me any decent forum or question site where it is part of the Etiquette that people should bump their posts, without adding additional information. What do you think would happen if everybody who ever asked a question starts bumping his question three times a day?

avatar image joeyaaaaa · Feb 03, 2013 at 08:43 PM 0
Share

oh well, it doesnt say edited on his post even still, so my rant was until now justifiable at the least,but out of respect removed. excuse me for another needless response, or bump. and i am aware i dont need to be directed anywhere. and what you said i find inconsiderate still. and rules? its okay to tell someone not to bump within a bump? okay.. and my comment as an answer was explained but you missed it? oh well. this community doesnt abide by its own rules why should i.

avatar image Loius · Feb 03, 2013 at 10:19 PM 0
Share

Stop being argumentative, immediately, please. Let it drop. Rules are there to be followed, regardless of who is or is not following them.

avatar image Wolfram · Feb 04, 2013 at 11:57 AM 0
Share

We need more information. $$anonymous$$ost importantly, your scene hierarchy. Is the camera a child of the player? a direct child? are there other objects/scripts involved? does the player have parents/ancestors? also we need all rotation values in the inspector of the player/camera hierarchy that are not controlled by script.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by OWiz · Feb 02, 2013 at 04:30 PM

A Vector3 goes "X,Y,Z". You're applying a 90 degree rotation to the Y axis, not the Z axis.

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 Eeppi · Feb 02, 2013 at 04:51 PM 0
Share

Like I said, rotationZ is 90, but it's applied on different script. 90 degree rotation on script2 is because of different reason, script 2 is just for rotating player model.

avatar image joeyaaaaa · Feb 03, 2013 at 01:29 PM 0
Share

unction Update(){ Limiter(); //This is just for limiting angle, don't $$anonymous$$d about this rotationX = script2.rotationX;

rotationY += Input.GetAxis("$$anonymous$$ouse Y") * sensitivity;

this part?^^^^ rotAngle = Quaternion.Euler(Vector3(rotationX,rotationY,rotationZ)); transform.rotation = rotAngle; } maybe make it Z+=mouzez

avatar image Eeppi · Feb 03, 2013 at 03:17 PM 0
Share

What? RotationZ is 90 degrees already and I don't want to change it..

avatar image joeyaaaaa · Feb 03, 2013 at 04:07 PM 0
Share

i misunderstood, i apologize

avatar image
0

Answer by Loius · Feb 03, 2013 at 08:05 PM

You need to rotate your camera pivot around its local X axis to your target heading on the YZ plane, and then rotate it around its default up axis (probably 'character's head up').

What you're doing now is rotating around local X and then local Y, after local Y is already pointing not-up. This makes it spin around a weird axis and gets you that odd look.

Generally you want to just parent your camera directly to your character, allow your character to rotate around its Y axis and only allow the camera to rotate on its own local X axis.

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 Eeppi · Feb 04, 2013 at 11:50 AM 0
Share

Sorry, but I didnt really understood what you mean now. $$anonymous$$aybe it's because english isnt my native language or I'm just stupid :P. "Generally you want to just parent your camera directly to your character, allow your character to rotate around its Y axis and only allow the camera to rotate on its own local X axis." What you mean with parenting and allow character to rotate around Y axis? I dont want character to rotate around Y axis (just camera).

avatar image
0

Answer by Wolfram · Feb 04, 2013 at 01:41 PM

In an object hierarchy, rotations depend and influence each other. Also, there are certain limitations when using Euler angles.

For example, if you fly to the North pole, your latitude approaches 90°. But once you are past the North pole, it doesn't go over 90°. Instead, it decreases again, but your orientation flips around, and your longitude flips by 180°. For a similar reason, you cannot set the X rotation in Unity larger than 90, or smaller than -90(=270). If you try it nonetheless, you will get strange behaviour.

I'm not sure what made you choose mouseX for your player, as this would tilt your whole player forward/backwards, while the Camera looks around left/right.

Instead, the usual approach is to have the Player turn left/right, and then use the Camera to loop up/down, without modifying the player. Combine this with local rotations instead of global ones, and you get this:

  • Player: keep X rotation at 0 and Z rotation at 90. Use MouseY as Y rotation.

  • Camera: keep both X and Z local rotation at 0! Use MouseX as Y(!) rotation.

So in your Camera script, use this:

 rotationX += Input.GetAxis("Mouse X") * sensitivity;
 transform.localEulerAngles=Vector3(0,rotationX,0); // a) local, b) eulerAngles, c) X as Y angle

And Player would be:

 rotationY += Input.GetAxis("Mouse Y") * sensitivity;
 transform.localEulerAngles=Vector3(0,rotationY,90);

Not sure what Limiter() does, but chances are it messes with this setup, so doublecheck it.

Note the Camera script is for rotationZ==90, it won't work like this for other Z orientations. If you want to modify the Z angle in your game, you first have to consider what should be affected - should the player reorient itself, or just the camera? Are you maybe trying to "walk on walls" etc.?

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 Eeppi · Feb 04, 2013 at 02:22 PM 0
Share

"I'm not sure what made you choose mouseX for your player, as this would tilt your whole player forward/backwards, while the Camera looks around left/right." $$anonymous$$y player is rotated 90 degrees so it's like inverted. I'm now going to try some things, i'll come back to tell if I get it working.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

13 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

Related Questions

First Person Camera Rotation 360 degrees on all axis 0 Answers

Camera X and Y velocity HELP! 0 Answers

fps MouseLook with animation applied to camera. 1 Answer

Using MouseLook script with LookAt function 2 Answers

Problem restoring proper camera rotation 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