- Home /
Camera follow rotating object
In all of my games that I've made so far I've made the camera a child of the main character. In this game the character is a sphere that you move around levels. I thought It'd be cool if I could have the ball rotate and move around. The only problem is that when the ball rotates so does the camera. Is there any way to achieve the effect of the camera following the ball besides parenting that wouldn't be too hard. I'm not really to worried about this, the visuals in my game aren't very good, so if it's going to be difficult i'll just deal with what i have currently.
Thanks.
Answer by team_eden · Feb 16, 2015 at 02:32 AM
Just add a script to your camera, and drag your ball as the target.
var target:GameObject; // drag your ball onto this
function Update() // set gameObject position the same as target, follow behind 0.5m Z-Axis
{ gameObject.transform.position=target.transform.position+Vector3(0.0,0.0,-0.5); }
If you want the camera to stare at the ball, add this to your update function
transform.LookAt(target.transform);
Go get'em!
Your answer
Follow this Question
Related Questions
Making a ball roll and keeping the axis? 2 Answers
Rotating camera around the sphere 2 Answers
pong rolling ball 1 Answer
Parenting without transform.rotation 1 Answer
Ball Rotating Help 0 Answers