- Home /
Mouse Aiming Follow Wrong Direction - Help
Hi everyone. So, i ve got this script in C#:
using UnityEngine; using System.Collections;
public class MouseLook3 : MonoBehaviour {
public float sensitivityX = 15F;
public float minimumX = -60F; public float maximumX = 60F;
float rotationX = 0F;
Quaternion originalRotation;
void Update () { rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.left);
transform.localRotation = originalRotation * xQuaternion;
}
void Start () {
if (rigidbody)
rigidbody.freezeRotation = true;
originalRotation = transform.localRotation;
}
public static float ClampAngle (float angle, float min, float max)
{
if (angle < -360F)
angle += 360F;
if (angle > 360F)
angle -= 360F;
return Mathf.Clamp (angle, min, max);
}
}
BUT it follows mouse while moving it up or down. how can i modify the script so it will follow it from right to left and opposite?
Can anyone help me with this coding?
Thanks in advance
Answer by ScroodgeM · Aug 31, 2012 at 09:40 PM
this row
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.left);
replace with
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
or
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.down);
not sure which direction you need
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How do i make zombies? 2 Answers
How can I get this script to work? 1 Answer
How do I get a script to make a character or object follow your player? 0 Answers
Object where the mouse is 4 Answers