0
\$\begingroup\$

I am going through the official introductory series "Roll a Ball" by the Unity team, and am on part 3 (youtube link.

There is a ball with mouse controls attached, and a Camera set as a descendant of the ball so that it follows it around. As the tutorial mentions, the Camera at this stage "rolls" along with the ball and is unusable.

The fix, as shown in the video, is the following added to Camera:

public GameObject player; # added through GUI
private Vector3 offset;
void Start () {
  offset = transform.position - player.transform.position;
}
void Update () {
  transform.position = player.transform.position + offset;
}

I understand in terms of C# syntax what this does, but I don't understand why it stops the camera from rotating. Isn't position controlled separately from rotation?

\$\endgroup\$
  • 2
    \$\begingroup\$ Did they also unparent the camera from the ball when applying this script to it? \$\endgroup\$ – DMGregory Aug 31 '17 at 19:51
1
\$\begingroup\$

The tranform of the GameObject has the properties "position" and "rotation"

These properties inherit their values from their parent unless you assign them different values.

But if the camera has no father and you only change its position, the value of its rotation is always constant

Good luck!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.