Hey guys!
I have a bit of a problem. I have a sphere that is rotating (think of a marble) and an empty object has it’s position constantly updated to match the position of the sphere. The empty object rotates with the iPhone’s accelerometer and the ball takes off in the direction that the empty object is facing. So far so good! Now, the problem is getting the camera to follow the ball. It is easy enough to get the camera to follow the ball left/right, up/down and backward/forward, but as far as being behind the sphere’s local z axis, nothing I do works.
To illustrate the problem, I’ve attached an embarrassingly crude image. On the left is the camera (rectangle) sliding over when the ball goes off to one side (BAD). On the right is the camera getting behind the sphere’s local z axis (this is where you guys come in) and looking at the sphere (LookAt(transform).
Now, I tried using the code below to make the camera stick behind the sphere’s z axis (actually, its the empty object’s z axis because the ball is spinning), but it does not work.
Camera.main.transform.localPosition.z=transform.localPosition.z-7.0;
I also tried taking the local part out of the camera end of the deal, but it didn’t work. Any thoughts?
Thanks