Hi, I am writing my own custom first person character controller. I have a problem though. Right now I am in the process of scripting in a pitching camera function that would allow the player to look up and down within a 180 Degree angle span along the X axis. All the script variables are setup in the inspector with all the transforms and values set up and attached already. The problem that I am having is that when I go into the play mode in the editor and start trying to pan up and down, it only shifts 1 degree in either direction and as soon as I let off the button it returns to zero (on the vertical axis). the camera is a child of a capsule object. any suggestions? ( semi-new to scripting about 1 1/2 year now)

here’s the inspector values…

alt text

then here’s my code…

// Create varibles ===============================================

// Manageing Object Transforms
var Objectpos : Transform;
var CamPos : Transform;

public var walkspeed : int=1; // Multiplier used to control walking speed
// Control cam rotation

var MinCamRot: float=-90.0;
var MaxCamRot: float=90.0;

// Controlling rotate speeds
var CamRotateSpeed : float=50;
var ObjectRotateSpeed : float=45;

//================================================================

function Update () {
Move ();
Rotate ();
}

// Moves object around based off user input
function Move ()
{// Start move function

// create local vars ===================

//====================================

// Get inputs for walk speed Shift control and normal
if (Input.GetKey(KeyCode.LeftShift)) // A sprint
	{walkspeed=5;} // A sprint
		else 
		{ // else 1
		if (Input.GetKey(KeyCode.LeftControl)) // A jog
			{walkspeed=3;}
				else 
				{walkspeed=1; // A walk
				}//2
		}// else 1


//Gets input up,down,left,right

if (Input.GetKey(KeyCode.UpArrow))
{Objectpos.Translate(Vector3.forward*walkspeed*Time.deltaTime);}

if (Input.GetKey(KeyCode.DownArrow))
{Objectpos.Translate(Vector3.back*walkspeed*Time.deltaTime);} 	
    
if (Input.GetKey(KeyCode.LeftArrow))
{Objectpos.Translate(Vector3.left*walkspeed*Time.deltaTime);}
		
if (Input.GetKey(KeyCode.RightArrow))
{Objectpos.Translate(Vector3.right*walkspeed*Time.deltaTime);}

} // end Move function



//Rotates the camera based on input
function Rotate ()

	{// Start Rotate function


// create local vars ===================
var campitch:float;
var newcamrot: Vector3;
//====================================

//Gets input A,S,W,D

//##### HERE IS THE PROBLEM ##############

// for camera pitch ( limited 180 degrees W and S keys )
  campitch+=Input.GetAxis ("Vertical");
  campitch=Mathf.Clamp(campitch,MinCamRot,MaxCamRot);
  CamPos.localEulerAngles= new Vector3(campitch,0,0);

//######################################################	 
	
// for character controller movement (Unlimited 360 Degree Movement D and A keys)    
if (Input.GetKey(KeyCode.A))
{Objectpos.Rotate (Vector3.down,Time.deltaTime*ObjectRotateSpeed);}

if (Input.GetKey(KeyCode.D))
{Objectpos.Rotate (Vector3.up,Time.deltaTime*ObjectRotateSpeed);}

} // end rotate function


Thanks,
Jacob

I fixed it. The problem was that the var campitch:float; was in the wrong place. it was being reset to zero every time the update was called. its the simplest things such as that in which can screw up all your code. lol