• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NovaDrox · Jul 09, 2017 at 05:22 AM · camerapositionvector3transform.positionvector3.lerp

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);
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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);
 }
 }
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NovaDrox · Jul 09, 2017 at 06:09 AM 0
Share

That would work, if I wasn't trying to do the lerp thing.

avatar image Jwizard93 NovaDrox · Jul 09, 2017 at 11:39 PM 0
Share

The camera is a child? perhaps you want to update it's localPosition ins$$anonymous$$d of its position.

avatar image NovaDrox Jwizard93 · Jul 10, 2017 at 02:16 AM 0
Share

I tired that and it still on the world axis.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

110 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trouble converting transform.position to C# 1 Answer

Moving the Camera Up and Down by pressing Key 2 Answers

How to detect VR camera movement? 0 Answers

How to find total distance from start to end of an array which stores positions in vector3? 2 Answers

Getting Vector3 in between two given Vector3 after given Distance. 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges