How to set the position for the rotating camera.

I have a GameObject at (0,0,0) and want rotate the camera around that if I hold mouse0 down and move the mouse along the x/y axis. I realized the rotation with camera.transform.LookAt(astroid.position);, but now i have a other problem. The position of the camera is not perfect set and the camera don’t stop to rotate around the astroid if i start to drag the mouse.

That I use for the position:

if (mouseDown){
    x += Input.GetAxis("MouseX");
    y += Input.GetAxis("MouseY");
}
 
       SetCameraRotation();
       SetCameraPosition(rotation, x, y);
}
 
void SetCameraRotation(){
    camera.transform.LookAt(astroid.position);
}
 
void SetCameraPosition(Quaternion rotation, float x, float y){
    Quaternion unit = Quaternion.Slerp(camera.transform.rotation, astroid.position, Time.deltaTime * 3);
    Vector3 position = unit * new Vector3(x * 0.1f, y * 0.1f, 0.0f) + camera.transform.position;
    camera.transform.position = position;
}

I now something is wrong with the position. Im new in Unity Scripting. Thanks for every help.
Greetings Chryb

If asteroid is a gameObject you need to use asteroid.transform.position

Ohh sorry my mistake, I have already a transform variable.

In the moment the camera rotate around the astroid in a eclipse form and if I begin to rotate it don’t stop.

I guess mouseDown is set to true as long as the mouse button is pressed, right?
You need do reset x and y to 0 after the mouse button is released.

Yes mouseDown is true if the mouse0 is pressed. I set x and y to 0 and it stop rotation by itself but while i rotate the camera around the object the distance is growing and the camera don’t rotate “clear” around the astroid (not in a perfect circle form).

Thats my code now:

		if (mouseDown){
			x += Input.GetAxis("MouseX");
			y += Input.GetAxis("MouseY");
		}
		
		Quaternion rotation = Quaternion.Slerp(camera.transform.rotation, Quaternion.Euler(x, y, 0), Time.deltaTime * 3);
		
		SetCameraRotation();
		SetCameraPosition(rotation, x, y);
		
		x = 0;
		y = 0;
		
	}
	
	void SetCameraRotation(){
		camera.transform.LookAt(astroid.position);
	}
	
	void SetCameraPosition(Quaternion rotation, float x, float y){
		Vector3 position = rotation * new Vector3(x * 3, y * 3, 0.0f) + camera.transform.position;
		camera.transform.position = position;
	}

Anyone a idea?