problem with camera

Hi all,
I’m new to Unity and Javascript ( decided to go with it for starters). I’m having an issue with the following code snippets. The script is attached to the camera.avatar is a gameobject that is moving at a constant speed along x. They both work exactly the same but the bottom one results in camera stuttering. Could someone explain why please.

function Update () {
transform.position = Vector3(GameObject.Find(“avatar”).GetComponent(Transform).position.x, 0, -60);
}


function Update () {
avatarx = GameObject.Find(“avatar”).GetComponent(Transform).position.x;
transform.position = Vector3(avatarx, 0, -60);
}

I’ve tried these scripts in late update as well, but exact same results. Interpolation is turned on on the avatar gameobject.

The best way to have a camera not jitter is to have the object control the camera. Currently you have the camera operating independently of the object and trying to keep up. The problem is that Unity does not always do scripts in the same order every frame. Thus causing jitteryness.

Thanks for the advice. Deleted the script and rewrote its contents as a function in the script that controls the moving rigid body.Still the same problem :S.

I’ve copied and pasted the whole thing below. Its functional but a bit of a skeleton as I’m trying to sort out the camera before working on the other bits.

private var camx = 0;
private var camy = 0;
private var camz = 0;
private var avatarx = 0;
var levelstartx = 0;
var levelstarty = 0;
var levelendx = 0;
var levelendy = 0;

var GameCamera : GameObject;
camx = GameCamera.transform.position.x;
camy = GameCamera.transform.position.y;
camz = GameCamera.transform.position.z;

var velocity = 20;
var jump = 10000;

private var gravity = -9.8f;

rigidbody.useGravity = false;
rigidbody.velocity = Vector3(velocity*1,0,0);

function Update () {

Debug.Log(Platform_status());
switch(Platform_status())
{
//When on floor
case “floor”:

//remove any bounce
rigidbody.velocity.y = 0;

//Left Key
if (Input.GetButton (“Left”)) {
rigidbody.velocity.x = velocity*-1;
}
//Right Key
else if (Input.GetButton (“Right”)) {
rigidbody.velocity.x = velocity*1;
}
//Up Key
else if (Input.GetButton (“Up”)) {//
rigidbody.velocity.y +=7;
}
//Down Key
else if (Input.GetButton (“Down”)) {
//crouch code here
}
break;

//When on Ceiling
case “ceiling”:

//remove any bounce
rigidbody.velocity.y = 0;

//Left Key
if (Input.GetButton (“Left”)) {
rigidbody.velocity.x = velocity*-1;
}
//Right Key
else if (Input.GetButton (“Right”)) {
rigidbody.velocity.x = velocity*1;
}
//Up Key
else if (Input.GetButton (“Up”)) {//
//crouch code here
}
//Down Key
else if (Input.GetButton (“Down”)) {
rigidbody.velocity.y -=7;

}
break;

//When Wall to the right
case “right_wall”:

break;

//When Wall to the left
case “left_wall”:

break;

//When in air
case “midair”:
//apply gravitational force
rigidbody.velocity.y += gravity * Time.deltaTime;
break;

}
Camera_Control();
}

function Platform_status() : String {
var hit : RaycastHit;
var platform : String;

if (Physics.Raycast (transform.position, Vector3.up,1)){
platform = “ceiling”;
}
else if (Physics.Raycast (transform.position, Vector3.down,1)){
platform = “floor”;
}
else if (Physics.Raycast (transform.position, Vector3.right,1)){
platform = “right_wall”;
}
else if (Physics.Raycast (transform.position, Vector3.left,1)){
platform = “left_wall”;
}
else {
platform = “midair”;
}

return platform;
}

function Camera_Control(){

if ( transform.position.x > levelstartx transform.position.x < levelendx){
camx = transform.position.x;
}

if (transform.position.y > levelstarty transform.position.y < levelendy){
camy = transform.position.y;
}

GameCamera.transform.position = Vector3(camx, camy , -60);

}

Ouch, that was silly, camx,camy and camz weren’t floats so it was rounding …uhm, I’m new.

Oh God, thank you very much, man! After look for so much time that one was the best workaround!

Thanks!!!