Search Unity

How to make a script camera pursuit the player?

Discussion in 'Scripting' started by rhendra, Feb 18, 2018.

  1. rhendra

    rhendra

    Joined:
    Dec 27, 2017
    Posts:
    44
    hey bosque...
    please help me.

    how to set up a script..."the camera can translate in x position. camera pursuit player, when player destroy, the camera stop translate and restart the camera position ( back to the first position point)"?

    please help me
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Don't you already have a thread about this question?
    I thought I already gave you an answer for this, too, as did 1 or 2 other people, maybe.
     
  3. ihgyug

    ihgyug

    Joined:
    Aug 5, 2017
    Posts:
    194
    In order to have the camera follow the player only in the X axis :
    You need to declare 2 Transform variables, one being main camera and one being Player.
    Then in the Update method you can use : MainCamera.position = new Vector3(Player.position.x, whatever you need as Y, whatever you need as Z).

    Then, idk your game, but you can simply check if the player is dead and if so, in the update, you move the camera in another manner.
     
  4. rhendra

    rhendra

    Joined:
    Dec 27, 2017
    Posts:
    44

    yea..but i cant understand about that becaue i am a new comer
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    My answer was very simple, in the other thread.

    Make a variable for the camera's script on the player. When the player dies, call a method on the script that stops it from moving. when the player moves/respawns, call a method to reposition the camera and resume moving.

    It can't get much simpler.
     
  6. rhendra

    rhendra

    Joined:
    Dec 27, 2017
    Posts:
    44
    i know the algorithm , i just cant write the script
     
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Please be more specific..

    Do you not know how to create a variable for the script on another script? Do you not know how to call a method or set a bool to not move? Do you not know how to call a method to reset a position? Do you not know how to save a position that's later used to reset to?
    :)
     
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'd suggest starting with both some stand alone C# tutorials and then afterward some basic Unity tutorials. After you have a minimal grasp of scripting C# for Unity then come back to this issue.
     
  9. rhendra

    rhendra

    Joined:
    Dec 27, 2017
    Posts:
    44
    no.. i am a beginner, i learn with the tutorial in youtube.. i dont know to much to arrangement a script. please help bro
     
  10. ihgyug

    ihgyug

    Joined:
    Aug 5, 2017
    Posts:
    194
    If you don't know how to write that script at all, as joe suggested, is better to follow C# tutorials (at least the basics) and after that unity tutorials. If you don't know something you can always look at Unity documentation.
    If we write a complete script we wouldn't help you, because when you encounter a similar problem what will you do? Ask to the community to write another script? That's not ideal at all.
    You need solid basics so you can at least understand the basic concepts, and so you will be able to edit scripts as your needs too, and not being stuck with a script someone wrote for you, or having to wait someone reply you on forum to do anything.
    The scripting section is to help people when they have errors in their scripts or they don't behave as they would like, not to write scripts to people. Otherwise you will never learn anything.