Search Unity

Player doesn't move when Camera follow player

Discussion in 'Scripting' started by mgamga3, Oct 11, 2022.

  1. mgamga3

    mgamga3

    Joined:
    Nov 9, 2021
    Posts:
    4
    upload_2022-10-11_17-35-53.png
    upload_2022-10-11_17-36-2.png

    I set camera to follow player only x axis
    but when I set camera, player stopped moving
    (but there is a change in the x-axis)

    Here's my player movement code & camera follow code


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CameraMove : MonoBehaviour
    6. {
    7.  
    8. public Transform target;
    9.     // Update is called once per frame
    10.     void Update()
    11.     {
    12.         transform.position = new Vector3(target.position.x, transform.position.y,-10);
    13.     }
    14. }
    15.  
    16.  
    17.  
    18.  
    upload_2022-10-11_17-35-53.png
     
    Last edited: Oct 11, 2022
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Moved.