Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

roll-a-ball camera offset problem

Discussion in 'Getting Started' started by jshrek, Feb 10, 2015.

  1. jshrek

    jshrek

    Joined:
    Mar 30, 2013
    Posts:
    220
    Hi

    Just installed Unity3D on my Mac earlier today and am going thru the roll-a-ball tutorial but am having a problem with the camera offset.

    When I run the game, the camera seems to jump to the same location as the ball, as opposed to being offset by initial positioning.

    Has anybody else experienced this same issue?

    This is the c# GameController.cs file which I think is identical to the one in the tutorial:

    Code (csharp):
    1. public class GameController : MonoBehaviour {
    2. public GameObject player;
    3. private Vector3 offset;
    4. void start () {
    5.    offset = transform.position;
    6.   }
    7. void LateUpdate () {
    8.    transform.position = player.transform.position + offset;
    9.   }
    10. }
    Thanks
    Jeff
     
    Last edited: Feb 10, 2015
  2. kdubnz

    kdubnz

    Joined:
    Apr 19, 2014
    Posts:
    177
    The roll-a-ball script attached to the Camera is
    CameraController.cs ... but GameController.cs should be ok provided it IS attached to the Camera.

    your void start ()
    should be
    void Start ()

    Because you aren't using the correct function, the offset variable will retain it's default values from the initialize statement
    .. which I assume is 0, 0, 0

    Also, regarding formatting code for the forums, please read here
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/

    Regards
     
  3. jshrek

    jshrek

    Joined:
    Mar 30, 2013
    Posts:
    220
    Yes changing start to Start resolved it!! I knew it was probably something simple I was missing.

    Thanks a lot :)

    PS - I fixed the posted code with code tags.
     
    Last edited: Feb 10, 2015
    Kiwasi likes this.
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Watch you case and spelling on the Unity magic methods. This is a very easy trap to fall prey to. And the compiler will give you no warnings or clues.