I am a bit confused on mouselook in c# and unity. I used the standard asset mouselook script as a template and tried to change it to suit my needs. When i used it, it seemed to work perfectly, but my vertical look made my character's model roate. When i looked up it would rotate and look up, which causes it to move forward. When i look down, it rotates the whole model and looks down, which causes it to move backwards. I figured this was due to the controller script i attached to the player. I wnat to do a small tweak, and rotate the character on its x-axis normally, but instead of the normal y rotation, to find the character's attached camera, and apply the rotation to that object.
I am a bit confused as to what this line does:
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX; I understand it puts the values from the transform rotation y value, and adds the mouse input x value, and the variable to change sensativity, but i am unsure why it uses the localEulerAngles.y value and not the x value. I change it to y, and the camera seems to just twitch around the same location when i move the mouse. Why does it do this?
I'm also having a problem with unity where the default (or essentially default) mouselook script doesnt work for rotation on y, (up / down). Why would this be? Here is my attached script:
PS: I have no other script that modifies rotation based on mouselook that interfere
asked Jun 08 '11 at 01:53 AM
Oh i just didnt want to spam and monitor like 20 different topics. if these got answered well this coukd be a nice topic to sticky if others have this same question, to reduce clutter.
answered Jun 08 '11 at 02:16 AM
Generally you have a character (body) which has a child object containing the camera (head and eyes). You rotate the body around Y (vertical) and head around X (pitch/tilt up/down). So typically a character controller does the movement of the body, and mouselook handles the head/camera.
Mouse input has X going horizontally and Y vertically. But you spin the model on the Y axis when moving the mouse in X, and head around its X when the mouse moves on mouse Y.
localEulerAngles are the pitch (x), yaw (y), and roll (z) angles of the object the script is on. They are in that object's coordinate space (not world space). It's a convenient way of saying, for example, 'look left' (by rotating -90 around Y) no matter which way the parent (body) is oriented.
If you want to 'lean' left/right, you'd use localEulerAngles.z. Well, if it's on the head (camera), that would lean just your head. To lean the body, do that on the parent of the camera (body).
If you put a mouselook script on the same object as the (child) camera, it just works. If you wanted to put mouselook on the body for some reason, you'd have to get the child and apply it, maybe like GetComponentInChildren(Camera).transform.localEulerAngle.x = 0; or something.
Unity supports image formats which Gimp can save to. If Gimp is your default editor for those file types, double-clicking a texture should launch it.
Unity should be loading .blend files (at least 2.49), so something must be strange. Don't use fancy shaders in Blender, keep it simple. Also Collada 1.4 is a good choice.
You should skin your models in blender (UV mapping). Each mesh in Unity can have one material, but meshes can have sub-meshes. A material contains one or more colors, one or more textures, and a shader (to combine those). So each mesh which has unique properties will have its own material, but you can certainly reuse the same material on different meshes. Blender has a pretty good set of UV mapping (unwrapping) tools.
You can google the rest. All this stuff has been asked and answered somewhere.
answered Jun 08 '11 at 02:25 AM
ok, thanks for the response. That makes sense with the mouse, to model rotation / movement. I didnt think that part of the code referenced that part. it looked like it was grabby the model's y rotation, and applying it to it's x rotation. Which confused me.
I imported the model from google sketchup by exporting it as google earth and extracting the .dae file form the output file (which is a zip structure). I then imported into blender and saved, with no errors. The exported model imports fine, but i dont want to export each time i make a minor change.
Do you happen to know why the script doesn't work when i revert it to its former state where it did work in modifying the x and y of the model based on the mouses x/y.
Do i have to use the get child method? well i think its a function in c#... or can just just reference the object in the inpscetor to test my code?
I wondered if unity would recognize gimps unique file format for its projects, rather than using more time and exporting each time.
NOTE TO MYSELF: Next time I could really leave a comment instead of a answer. I am such a dummy! I could also really understand how this site works. The fact that is not a forum is unclear to me. - Orangelightning.