- Home /
Camera Following Ball Going Everywhere
HI, I have a game involving a ball that will roll, I'm using it as a rigidbody because it is easier to use physics like this, but when I make the ball a parent to the main camera the camera rolls with the ball so it is impossible to play the game. If anyone has a script or an idea that could help me this would be great. Thanks!
Answer by bentog · Dec 24, 2012 at 05:19 PM
The camera is rotating the same way as the ball! Instead of making the camera a child of the ball, try writing a script that makes the camera always in the position of the ball, but a little taller and behind it. Like this:
var sphere : Transform; //you should assign your sphere to this in the inspector
var height : float; //height of the camera
var behind : float; //the distance the camera will stay from the sphere behind it
function Update ()
{
transform.position = sphere.transform.position + Vector3(0, height, -behind); //makes the cam position the same as
// the ball, plus height and distance behind
}
Assing this script to the camera, set the variables, make sure the camera is not a child of the ball anymore, and it's done. I tested and it works.
Answer by GameDev.Pro · Jan 08, 2013 at 01:58 AM
Ok Thank you so much.
You should have posted this as a comment to my answer. Also, can you mark my answer as correct if it worked?
Your answer
Follow this Question
Related Questions
Make a rolling ball always on ground without falling when reaching the edges of the map 1 Answer
The Physics of Ball Spin in Tennis, Topspin and Backspin 3 Answers
Kick a Ball - Add Force? 2 Answers
Adding Force to a rolling ball 1 Answer
How do I move my object through physics with my keyboard? 1 Answer