- Home /
Camera snapping to invisible grid when in scope mode.
Hi there, sorry this is being asked again; I found this problem a little while back but cant seem to track it down now.
Anyway, my issue is that I coded a Mouse Look script which works smoothly and nicely for my mini game, however, I also added another camera as a child and coded this in as a "Scope" for my weapon. However, this camera seems to snap to an invisible grid rather than the same smooth motion the normal camera has. The problem with this is that I have targets that can only be shot whilst looking through the scope at certain points and unfortunately the problem makes it quite difficult to be accurate. Below is my mouse look script in case it is needed and also a short clip of the problem:
#pragma strict
public enum RotationAxis {MouseX = 0, MouseY = 1}
var RotationAxisRotationXY = RotationAxis.MouseX || RotationAxis.MouseY;
/** Define variables for X Axis which include
Sesnitivity and minimum and maximum rotation of axis X **/
var sensitivityX : float = 400f;
var minimumX : float = -360f;
var maximumX : float = 360f;
var RotationX : float = 0f;
var OriginalRotation : Quaternion;
var XQuaternion: Quaternion;
/** Define variables for Y Axis which include
Sesnitivity and minimum and maximum rotation of axis Y **/
var sensitivityY : float = 400f;
var minimumY : float = -25f;
var maximumY : float = 25f;
var RotationY : float = 0f;
var YQuaternion: Quaternion;
function Update () {
if(RotationAxisRotationXY == RotationAxis.MouseX) {
RotationX += Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime;
RotationX = ClampAngle (RotationX, minimumX, maximumX);
OriginalRotation = XQuaternion = Quaternion.AngleAxis (RotationX , Vector3.up);
transform.localRotation = OriginalRotation * XQuaternion;
}
if(RotationAxisRotationXY == RotationAxis.MouseY) {
RotationY -= Input.GetAxis ("Mouse Y") * sensitivityY * Time.deltaTime;
RotationY = ClampAngle (RotationY, minimumY, maximumY);
OriginalRotation = YQuaternion = Quaternion.AngleAxis (RotationY, Vector3.right);
transform.localRotation = OriginalRotation * YQuaternion;
}
}
static function ClampAngle (Angle: float , min: float , max: float ) : float {
if(Angle < -360){
Angle += 360;
}
if(Angle > 360){
Angle -= 360;
}
return Mathf.Clamp (Angle, min, max);
}
Video: http://www.youtube.com/watch?v=5XDmHwAwDck&feature=plcp
Thanks
Your answer
Follow this Question
Related Questions
How to fix weird camera rotation? 0 Answers
Camera Movement 1 Answer
,iOS WebCamera Texture GetPixels() call returns only black colours? 1 Answer
Camera flickers between scenes 2 Answers
Don'tDetroyOnLoad | issue 1 Answer