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. Dismiss Notice

Why this script move the camera from side to side in between to points ?

Discussion in 'Scripting' started by Chocolade, Jul 30, 2016.

  1. Chocolade

    Chocolade

    Joined:
    Jun 19, 2013
    Posts:
    916
    I wanted to make my character to move/walk between two points positions but the camera is moving.

    Code (csharp):
    1.  
    2. [LIST=1]
    3. [*]privateVector3 pos1 =newVector3(-4,0,0);
    4. [*]privateVector3 pos2 =newVector3(4,0,0);
    5. [*]publicfloat speed =1.0f;
    6. [*]voidUpdate(){
    7. [*]transform.position =Vector3.Lerp(pos1, pos2,(Mathf.Sin(speed *Time.time)+1.0f)/2.0f);
    8. [*]}
    [/LIST]
    Why the camera is moving from points to points ? transform is not the character the gameobject ?
    I also tried to make Transform _transform; and then getcomponent<Transform> but still it's moving the camera not the ThirdPersonController i attached the script to.
     
  2. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    Just put it on the gameObject you want to move. But it will move also all the children of your gameObject, so maybe your cam is a child of transform
     
  3. Chocolade

    Chocolade

    Joined:
    Jun 19, 2013
    Posts:
    916
    Yes thanks.