- Home /
FPS mouse look script error unity 3d. help!!!!
Hi. iv'e tried to create new FPS mouse look script but when i done it it shows me errors:
Assets/FPS Scripts/FpsMouselook.js(4,9): BCE0043: Unexpected token: var. Assets/FPS Scripts/FpsMouselook.js(52,52): BCE0043: Unexpected token: float. Assets/FPS Scripts/FpsMouselook.js(61,1): BCE0043: Unexpected token: .
FPS script info:
public enum RotationAxis {MouseX = 0, MouseY = 1
var RotationAxisRotationXY = RotationAxis.MouseX || RotationAxis.MouseY;
//We are defining variables needed for our X axis motion. This will include
// sensivity and the minimun and maximum of the x axis rotation.
var sensitivityX : float = 400f;
var minimumX : float = -360f;
var maximumX : float = 360f;
var RotationX : float = 0f;
var OriginalRotation : Quaternion;
//Now lets set variables for the y axis so the player can look up and down
//using the mouse.
var RotationY : float = 0f;
var minimumY : float = -25f;
var maximumY : float = 25f;
var sensitivityY : float = 400f;
function Update () {
if(RotationAxisRotationXY == RotationAxis.MouseX){
RotationX += Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime;
OriginalRotation = XQuaternion = Quaternion.AngleAxis (RotationX . Vector3.up);
transform.localRotation = OriginalRotation * XQuaternion;
}
if(RotationAxisRotationXY == RotationAxis.MouseY){
RotationY -= Input.getAxis ("Mouse Y") * sensitivityY * Time.deltaTime;
OriginalRotation = YQuartenion = Quaternion.AngleAxis (RotationY . Vector3.right);
transform.localRotation = OriginalRotation * YQuaternion;
}
}
static function ClampAngle (Angle, min, max) float {
can someone help???
Answer by Dasherz · Aug 26, 2012 at 11:39 PM
I did that tutorial a while ago. Here is my code, I got it working also. edit: I only saved it so it would look with the Y axis, but you can just copy and paste and add in the X axis one.
public enum RotationAxis {MouseY = 1}
var RotationAxisRotationXY = RotationAxis.MouseY;
var OriginalRotation : Quaternion;
// Now lets set the variables for the y axis so the player can then look up and down
// using the mouse.
var RotationY : float = 0f;
var minimumY : float;
var maximumY : float;
var sensitivityY : float = 400f;
var cylinderZ : GameObject;
function Start( )
{
minimumY = -75f;
maximumY = -25f;
}
function Update () {
//print("mouse Z" + Input.mousePosition.x + " cylinder Z" + cylinderZ.transform.position.x);
if(Input.mousePosition.x >= cylinderZ.transform.position.x)
{
minimumY = 25f;
maximumY = 75f;
}
if(Input.mousePosition.x <= cylinderZ.transform.position.x)
{
minimumY = -75f;
maximumY = -25f;
}
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, min, max): float {
if(Angle < -360){
Angle += 360;
}
if(Angle > 360){
Angle -= 360;
}
return Mathf.Clamp (Angle, min,max);
}