- Home /
Camera drifting away when only rotating?
I have this script attached to the camera:
void Update () {
transform.LookAt(Vector3.zero);
transform.Translate(Vector3.right * Time.smoothDeltaTime);
}
But when the game runs really long the camera is further away. I noticed this yesterday when I had a test build running in the background. The object it was rotating around got really "small". Today I went AFK for a couple of hours and it was even smaller.
I guess it is because I actually move the camera on it's local axis and since it has a lookAt target this axis changes. But it is not rotating 100% correctly. It is not causing real problems but is there a fix to it?
$$anonymous$$aybe parent the camera to an empty at the location you are rotating around? Then just rotate the empty itself!
Answer by Berenger · Jan 20, 2015 at 04:35 PM
If you wan't the camera to rotate around a point, you could, amongst other possibilities, set the position with trigo :
transform.position = point + new Vector3( Mathf.Sin(Time.smoothDeltaTime * speed) * distance, height, Mathf.Cos(Time.smoothDeltaTime * speed) * distance);
Then tweak speed, distance and height to get it right.
i dont get what point is. is it a vector3 or a transform?
Your answer