# Camera follow an object within a circle?

Hey Guys,

I kinda loving this community, right of the bat. Quite comprehensive.

Problem

I am making a game on unity3d and the camera is follow a character in Top-Down view (X-Z Plane). I would like the camera
to follow the player once he moves beyond a radius from the center of the camera. The camera should move at equal distance in such a way that the player is at the tip of circle.

Circle is something like this.

I would also like the camera to not to move when the player is inside the circle.

Approach

Hence to solve it, I thought I could use

x^2 + z^2 = r^2
where (x,z) are co-ordinates and r is the radius.

Could you guys guide me, as of how to accomplish it.

Thank you,

kathir.

You could do some thing like this

``````distance = Vector3.Distance(target.position, Camera.main.transform.position);
``````

Then if “distance” goes above say 60 or whatever size you want you circle then tell the camera to follow something like

``````Camera.main.transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);
``````

Use a variable for your “moveSpeed” to match your characters speed, I think that should do it.

Hope that helps you out.