- Home /
Getting a scrolling camera to orbit around a circular walkway, following the player?
Gentlemen!
Currently, I'm making a scene where the area the player can move around in is basically a ring (A walkway going around a circular structure). What I'm wanting to do is make the camera follow the player as they move around, but instead of it looking at them directly, I want it to always look at the center of the circular structure:
GRAY is the structure, GREEN is the walkway, PURPLE is the player, RED is the camera and its path.
Basically, the line should always be going through the player, and to the point at the center of the structure. When the player moves, the camera should follow the path of the red ring.
How should I go about doing this?
$$anonymous$$c$$anonymous$$utton, did my solution below not help?
Answer by KeithK · Apr 07, 2011 at 06:54 AM
Give this a shot.
Create an Empty GameObject. This will be your CameraPivot point and will be positioned in the center of your circular level, so where your Camera path ends in your diagram above.
Take your Camera, and make it a child of your CameraPivot. This will ensure it inherits the transforms of CameraPivot.
You will have to make sure you have your Camera looking at the "back" of your CameraPivot. So basically as long as your Camera has a 180 rotation on it's Y-axis and is looking at the CameraPivot.
Now the magic!
In your CameraPivot script create a target variable. This target will be your player character. I'm going to write this in C#, but can change it if you're using JS and can't port it.
public Transform targetLookAt;
After assigning this script to your CameraPivot, you can drag your player instance from the Editor onto the "Target Look At" property in the Inspector. Or you can assign it however else you want really.
So now, all you need to do is keep your CameraPivot looking at your targetLookAt and your Camera will adapt :)
void Update()
{
transform.LookAt(targetLookAt);
}
In your Camera you can just add, if you want, whatever logic you want to use to keep the Camera a certain distance from it's Parent's (the CameraPivot) targetLookAt.
Ah, excellent. There's a bit of a lack in camera control, but this will do nicely.
The camera spins wildly around it's Z when the camera is at the pole.