Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 atamjak2016 · Feb 24, 2019 at 06:01 PM · cameratransformcamera-movementtransform.positioncamera movement

Need help updating camera position to go above the player

I'm quite new to this. What I'm trying to do is use a script to set the Camera's position to be the same as the Player's position. I used a script to do this instead of parenting so that the camera retains it's rotation information. The problem here is that the camera is now inside of my Player, but I just want the camera to be slightly above and behind the player, in order for the Player to be seen. Here's my camera script--

 public class CameraMove : MonoBehaviour
 {
     
     public Transform PlayerTransform;
     public Transform CameraTransform;
     public bool PlayerAlive = true;
 
     void Update()
     {
         if (PlayerAlive == true)
         {
             CameraTransform.position = PlayerTransform.position;
         }
     }
 }
 

I took the Player's Transform and put it into the script in the Inspector window, same thing with the Camera Transform.

I'm assuming there's some way to add/subtract to the xyz-axis(es?), but I've got no idea how to do that. Any help?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by SteenPetersen · Feb 24, 2019 at 06:14 PM

The problem is that that code will make the camera have the exact same position as the player. you dont want that. you want an offset:

  public class CameraMove : MonoBehaviour
  {
      public Transform PlayerTransform;
      public Transform CameraTransform;
      public bool PlayerAlive = true;
      [SerializeField] Vector3 offSet;
  
      void Update()
      {
          if (PlayerAlive == true)
          {
              CameraTransform.position = PlayerTransform.position + offSet;
          }
      }
  }

Then, in the inspector, set your offset to be about {0, 10, 0} and test that. That should set the camera about 10 units on the y Axis (making the assumtion that (Y) is "up" for you) above the player.

Comment
Add comment · Show 2 · 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 atamjak2016 · Feb 25, 2019 at 10:55 AM 0
Share

Thank you so much for the help.

avatar image SteenPetersen atamjak2016 · Feb 25, 2019 at 11:18 AM 0
Share

You're welcome!

avatar image
0

Answer by Cornelis-de-Jager · Feb 24, 2019 at 09:08 PM

What you want to do is create an empty gameobject, parent it to the Player and move it to the position you want the camera to be. You then simply create a script where the camera follows the position of that empty gameobject.

 public class CameraFollow: MonoBehaviour {
     
     pubic Transform objToFollow; // <--- Reference that object here    
     public float followDelay; // Smooths out the following effect
         
     void LateUpdate => transform.position = Vector3.Lerp (transform.position, objToFollow.position, followDelay);
 }
Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

186 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 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

How to make camera move like it does in the scene viewport? 0 Answers

Move camera when mouse is near the edges of the screen 1 Answer

Confuse about transform.InverseTransformPoint 1 Answer

Make a camera to Follow two players 2 Answers

Clamping cameras with different rotation 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges