- Home /
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:
Click attachments to see bigger picture. Playerrota = script2, you don't probably need moving script information but it came with screenshots. Mouselook = script1.
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?
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.
Stop being argumentative, immediately, please. Let it drop. Rules are there to be followed, regardless of who is or is not following them.
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.
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.
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.
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
What? RotationZ is 90 degrees already and I don't want to change it..
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.
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).
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.?
"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.