Jittery camera

What am I doing wrong with this script?

It works fine but the terrain is a little jittery in the camera - as this scipt is attached to a camera

ta

var x=90.0;
var z=360.0;

var xpos;
var zpos;

function Update () {

xpos = 1000+(70000 * (Mathf.Sin(x)))*Time.deltaTime;
zpos = 1000+(70000 * (Mathf.Cos(z)))*Time.deltaTime;

transform.position=Vector3(xpos,10,zpos);
transform.LookAt(Vector3(1000,10,1000));

x=x-0.01;
z=z-0.01;

}

Are you tryin to move the camera in a circle?

Try converting the angle from degrees to radians… I may be wrong but I think sin and cos need radians inputted.

Probably a better way of rotation in a circle is to make an empty gameobject to use as the circle origin and parent the camera to it. You can then just move the camera to the radius you want in the editor and rotate the empty gameobject.

I don’t think sin and cos are very efficient and quite CPU intensive.

Regards,
matt.

Going by the script in your other topic, what I meant by using deltaTime was this:

var x=1.0; 
var z=1.0; 

function Update() { 
	transform.position=Vector3(60 * (Mathf.Sin(x)), 3, 60 * (Mathf.Cos(z))); 
	transform.LookAt(Vector3(1000,10,1000)); 
	x += Time.deltaTime; 
	z += Time.deltaTime;
}

I don’t know what you’re trying to do exactly though.

As far as sin and cos, they are CPU-intensive, but that’s in relative terms…you’d need thousands per frame on any halfway-decent CPU to have a real effect on the framerate.

–Eric

Thanks for all your help!!

I think that my math is ok … isnt it??

Yeah it would be easier to attach the camera to an object and rotate it … but I have headed down the math path. :?

I am trying to make the camera circle an object and look at it … but yeah the camera is all jittery and wild :slight_smile:

I thought my programming was the culprit?

As well as using a smaller angle (in radians, as was mentioned above), you need to pass the same parameter to both the sin and cos functions. You are passing x to sin and z to cos - it should be the same angle in both cases.