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

Adding Values to the Camera (NEWBIE LEARNER)

Discussion in 'Scripting' started by deadly3652, Sep 21, 2015.

  1. deadly3652

    deadly3652

    Joined:
    Sep 21, 2015
    Posts:
    8
    how do i add values to my variable offset because the camera looks directly in first person i am not making an fps and if i was i would have to still make a turn camera function. but back to the point how to i make the camera's ZED, and X access to zoom out a bit on my sphere

    ///CODE BELOW/\\\\\\
    using UnityEngine;
    using System.Collections;

    public class CameraController : MonoBehaviour
    {
    //The target player object
    public GameObject player;

    //The offset distance at which camera should stay
    private Vector3 offset;

    void start()
    {
    //This will calculate the gap between player and camera at startup
    offset = transform.position - player.transform.position;
    }

    void LateUpdate()
    {
    //Update camera position based on player position
    Vector3 Cameraposition = player.transform.position - offset ;

    //Apply the final position
    transform.position = Cameraposition;
    }

    }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    please use [code ][/code ] tags when pasting code into the forums, really helps with readability, add lines numbers (helps with error messages which also have line numbers) etc., there is a sticky on them at the top of the scripting forum.

    I've read you're message above your code a few times and I'm not entirely sure what you are trying to do o_O perhaps tell us what you are trying to do rather than what you aren't?
     
  3. deadly3652

    deadly3652

    Joined:
    Sep 21, 2015
    Posts:
    8
    ........
     
  4. Max_Bol

    Max_Bol

    Joined:
    May 12, 2014
    Posts:
    168
    After reading the question 3 times, am I right that you wish to do a 3rd person controlled camera?
    If that's the case, this is a link toward a bunch of video tutorial that will give you quite a good overview (and scripts) for what you might be looking for :
    http://www.3dbuzz.com/training/view/3rd-person-character-system/simple-character-system/

    Even if you might not need the character related stuff, the "TP_Camera" related video might help you out. I still suggest watching the whole thing to get a better overview of everything you need or not from it.