Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Is it possible to lock a camera onto one side of an object?

Discussion in 'Scripting' started by FreshCoder-731319, Jun 5, 2020.

  1. FreshCoder-731319

    FreshCoder-731319

    Joined:
    May 21, 2020
    Posts:
    17
    Being testing for while to find out how to make a camera follow a side of an object. For instance if i had a cube with 3 different camera angle buttons; main camera button faces the front, side camera angle will face the side and the 3rd angle button will face above.

    The problem is having a rotation button included, a user can rotate a cube object then can decide to click the side button after. This will then activate the side camera but the user will not see that side due to the rotation moving the position instead it could potentially see a corner.

    Is it possible for a camera to targer a side object and following where ever it turn ?
     
  2. MatrixQ

    MatrixQ

    Joined:
    May 16, 2020
    Posts:
    87
    If you set up a camera as a child of the object it is supposed to follow, its position will always be relative to the parent object. That's exactly the bahavior you want.
     
    Joe-Censored likes this.
  3. FreshCoder-731319

    FreshCoder-731319

    Joined:
    May 21, 2020
    Posts:
    17
    Thanks for the reply but unfortunately in my case it did not work.
     
  4. MatrixQ

    MatrixQ

    Joined:
    May 16, 2020
    Posts:
    87
    It should look something like this. If you then turn the cube, it definitely turns the cameras with it.
    upload_2020-6-5_15-33-58.png
     
  5. FreshCoder-731319

    FreshCoder-731319

    Joined:
    May 21, 2020
    Posts:
    17
    I believe its to do with the project i am working on the 3d gameobject is imported from a external software
     
  6. MatrixQ

    MatrixQ

    Joined:
    May 16, 2020
    Posts:
    87
    Hmm. In that case, create an empty game object, import the external 3d object as a child of this empty game object and use the empty game object as a wrapper to turn instead of the gameobject itself. The cameras should be children of the empty object then.
     
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,724
    I don't see how this changes anything.

    Please volunteer more information and it will be easier for people to help you:
    • Screenshots of what's happening
    • Screenshots of your object hierarchy
    • Scripts you're currently using for camera following
     
    Joe-Censored likes this.