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
using UnityEngine;
using System.Collections;
/// MouseLook rotates the transform based on the mouse delta.
/// Minimum and Maximum values can be used to constrain the possible rotation
/// To make an FPS style character:
/// - Create a capsule.
/// - Add the MouseLook script to the capsule.
/// → Set the mouse look to use LookX. (You want to only turn character but not tilt it)
/// - Add FPSInputController script to the capsule
/// → A CharacterMotor and a CharacterController component will be automatically added.
/// - Create a camera. Make the camera a child of the capsule. Reset it’s transform.
/// - Add a MouseLook script to the camera.
/// → Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)
[AddComponentMenu(“Camera-Control/Mouse Look”)]
public class MouseLook : MonoBehaviour {
public bool rotateChildCameraforUpDown; //used to specidy to use my modified camera look for up / down
public Camera childCamera;
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationY = 0F;
void Update ()
{
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
if(rotateChildCameraforUpDown==false)
{
rotationY = transform.localEulerAngles.x + Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else
{
rotationY = transform.localEulerAngles.x + Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(0, rotationX, 0);
//transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.rotation.y, 0);
}
}
void Start ()
{
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
}
What does localEulerAngles actually mean? I looked it up on the documentation, but am still a bit confused. I understand that it stores the objects rotation according to the parent object as a quaternion. I understand the quaternion part, but by parent, it means, that whatever parented object(the objects are parent / child)will tell its rotation as referenced form the parent object, rather than form 0,0,0.
How do i apply a rotation to a child camera object? I defined a variable as type “camera” and used the inspector to assign the child, but i try to assign rotation to only its y values, but how do i keep the other values the same. Would i use “localEulerAngles.x” and “localEulerAngles.z”?
I have the latest blender 3d program, and i cannot import the .blend project files directly. i have to export them as an .fbx. I have unity 3.3 pro.
Does unity support gimp? or do i have to always export to photoshop formats?
When i model, do i HAVE to apply the texture as a skin in unity, or can i have each part be a different texture and just reference them? Doesn’t unity support model texture coordinates that tell locations of materials for meshes?
If i have to use a skin, would i be forced to use “uv unwrapper” or similar program to create the base skin and then add in my textures to create the model skin?
Do any of you know any updated fps tutorials, and tutorials that cover gui and menus?
I hope i’m not asking too many questions at once. I just love unity so far and need a little help aside from documentation.
I hope I’ve provided enough information to be able to let you all help me, if not just ask for other information.