Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
2
Question by aidenkael · Nov 09, 2013 at 01:04 AM · targetboo

Main Camera follows player?

I have a script attached to my main player, and I want to set the Main Camera to follow behind my player in the same script. Is there some way to do this by using the players position minus 1.5 for the cameras position?

I think I need to use a target variable correct? How would I do that?

Comment
Add comment · Show 1
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 kiwi koder · Nov 09, 2013 at 04:52 AM 0
Share

$$anonymous$$aybe import the Character Controller and use that...

5 Replies

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

Answer by Aspirer · Nov 09, 2013 at 01:52 AM

All you need to do, is make the Main Camera a child of the Main Character object (drag and drop in the hierarchy menu.) Then, set the camera's transform to (0, 0, -1.5).

As a child, the camera will move when the player moves, and it's position will use the player's position, modified by the -1.5.

Meaning, if your player is on X: 0, Y: 0, Z: 0, the camera will be X:0, Y:0, Z: -1.5. If the player moves to 100, 100, 100, the camera will be 100, 100, 103.5

No need for any scripting to do this.

Comment
Add comment · Show 1 · 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 SevenLaggs · Mar 30, 2020 at 01:40 AM 0
Share

I know its been a long time but but i wanted to ask if you could tell me what im doing wrong. I set it under my played but i cant move it along z and now its floating over my players head

avatar image
8

Answer by Huacanacha · Nov 09, 2013 at 02:01 AM

Take a look at the SmoothFollow in the Standard Assets scripts, which is included with the free version of Unity. That allows you to set a follow distance and height, and will smoothly follow your character around.

You apply this script to the camera, and use the inspector to set the follow distance, height, and target (the player game object in your case).

Note: if you don't install the standard assets with Unity you can download them from the Asset Store.

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 Francheesecake · Nov 13, 2015 at 04:42 PM 0
Share

I have a small question, does it consider rotation? I mean, if a character changes the direction it's facing, the camara will do the same?

avatar image Troas Francheesecake · Nov 13, 2015 at 04:51 PM 0
Share

In order to rotate you will need to start scripting some.

I created a script a while ago that rotates the camera with the player it's pretty simple. I'll go look it up for you later today and try to explain it.

avatar image Huacanacha Francheesecake · Nov 13, 2015 at 05:55 PM 0
Share

Yes, with SmoothFollow the camera will follow the rotation of the player. The difference between using this script and just parenting the camera on the target transform (i.e. making the camera a child of the player) is that the movement will be damped/smoothed which helps avoid sudden or jerky camera movement.

@Troas we are already talking about a script. Unity provides standard assets for basic camera scripting that you can just use and set the parameters on.

avatar image
2

Answer by Fr0stbite · Nov 09, 2013 at 11:30 AM

http://answers.unity3d.com/questions/38526/smooth-follow-camera.html

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
avatar image
0

Answer by argertboja · Jun 21, 2017 at 03:35 PM

@aidenkael You don't have to do this by scripting because if you make your camera a child of the player it will automatically follow the player. However if you want to make it by scripting you can use the below C# code:

 void Update () {
     // Temporary vector
     Vector3 temp = player.transform.position;
     temp.x = temp.x - x;
     temp.y = y;
     temp.z = temp.z - z;

     // Assign value to Camera position
     transform.position = temp;
 }

where x, y, z are the variables which define the difference of the camera position to that of the player.

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
avatar image
0

Answer by StrawProductions · Feb 23, 2021 at 08:58 PM

hey im new to unity, exactly which XYZ things do i hav to change for the camera, i just see three options @Aspirer

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

26 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

Related Questions

Nav agent doesn't go to target 1 Answer

Centering camera between my player and a selected object. 0 Answers

Player target enemies automatically 0 Answers

Dynamic load of Image target - ARKit 0 Answers

Target lead (aim ahead) problem 1 Answer


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