- Home /
 
Child GameObject is aligned to world axis and not the parents axis (UPDATE)
This is driving in me insane, and it worked before, but not now. I have my player camera set up as a child of the player. Then I have some small key pressing statements to change the position of the camera, but when I press one of them, it sets the camera to the world axis and not the player. The second thing I need to figure out is how to lerp each position, so when you press a new position, it smoothly goes to that position instead of jumping it.
UPDATED:
So, I figured out my lerping problem, but I am still stuck with my child object not moving around the player's axis. It's still stuck to the world's axis.
Here's my script: [Header("Camera Info")]
 [SerializeField]
 private GameObject PlayerCamera;
 [SerializeField]
 private Transform PlayerCamPosition;
 [SerializeField]
 private Transform FocalPoint;
 public float Smoother;
 [Space]
 public Vector3[] CameraPositions;
 private Vector3 Current;
 private void Start()
 {
     if (Camera.main != null)
     {
         Camera.main.transform.gameObject.SetActive(false);
     }
     Current = CameraPositions[0];
 }
 private void Update()
 {
     SetPosition();
     ChangeCamPosition(Current);
 }
 private void SetPosition()
 {
     PlayerCamera.transform.LookAt(FocalPoint);
     if (Input.GetKeyDown(KeyCode.Alpha1))
     {
         Current = CameraPositions[1];
     }
     if (Input.GetKeyDown(KeyCode.Alpha2))
     {
         Current = CameraPositions[0];
     }
     if (Input.GetKeyDown(KeyCode.Alpha3))
     {
         Current = CameraPositions[2];
     }
 }
 private void ChangeCamPosition(Vector3 Position)
 {
     PlayerCamera.transform.position = Vector3.Lerp(PlayerCamPosition.position, Position, Smoother);
 }
 
              Answer by kaway · Jul 09, 2017 at 06:02 AM
Instead of changing the position of the cameras better Create 3 chambers And place them where you want them to go each and there Comes with a new and simpler script
 public class Camera: MonoBehaviour {
 
 public GameObject[] Camera;
 
 Void Start() {
 }
 
 Void Update () {
 if (Input.GetkeyDown(KeyCode.Alpha1)){
 Camera[0].SetActive(true);
 Camera[1].SetActive(false);
 Camera[2].SetActive(false);
 }
 if (Input.GetkeyDown(KeyCode.Alpha2)){
 Camera[0].SetActive(false);
 Camera[1].SetActive(true);
 Camera[2].SetActive(false);
 }
 if (Input.GetkeyDown(KeyCode.Alpha3)){
 Camera[0].SetActive(false);
 Camera[1].SetActive(false);
 Camera[2].SetActive(true);
 }
 }
 }
 
              That would work, if I wasn't trying to do the lerp thing.
The camera is a child? perhaps you want to update it's localPosition ins$$anonymous$$d of its position.
Your answer