Camera to follow the player in the form of radius

Hello Devs,

What do I have :

A top-down game where a camera follows the player. It is on X-Z plane. For now the camera follows the player across X-Z plane by the player’s global position and mainatains a certain height from the player. The center of the level is a cylinderical object thats spans for the entire height of the level.

When do I think would happen?

The player is free to roam around the level (X-Z) but at certain point, the player might tend to get near the cylindrical object. Hence I would like to change the behaviour of the camera at that particular instance.

What do I want :

When the player reaches near a cylindrical object (say Radius ‘r’ from the center), I would like to camera to lock its position i.e. maintain the distance (radius) from the cylinder. But as the player has the freedom to move around the cylinderical object, there are exceptions when it gets out of the camera’s view. Hence at this instance, I would like the player to rotate around the cylinderical object when the player does so.

Image Representation :

  1. First Image :
    The camera follows the player above its global position.
  2. Second Image : The player enters a radius ‘r’ from the center of the cylinder. Hence the player stops following and locks it’s distance from the player.
  3. Third Image : An exception that is caused is the movement of the player within the radius ‘r’ from the center. Hence in order to have the player inside the view of the camera, the camera follows the player by maintaining a distance and thus suffer rotation.
  4. Fourth Image :Player moves and so does the camera. The rotation is similar to a merry-go-round.

Thank you once again,



This isn’t really an answer.

But you could take a look at transform.RotateAround(). I set up a scene like you described and used the position of the cylinder as the point to rotate around.

Then I used Vector3.Distance() to check how far the camera was from that point. I then rounded the value it gave me back Mathf.Round() and tried an If statement to start rotating when I was a certain distance.

if ( distance to cylinder <= radius or a suitable distance)
    transform.RotateAround(cylinder, vector3.up, rotateSpeed * time.deltatime);

I also cast a ray from the camera to the player to check if anything was in the way such as the cylinder and then stated rotating like above.

Problem is it behaves differently depending on how your camera is setup, plus it only rotates one way around at the moment.

Hope its of some use to you until someone more knowledgeable comes along.