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 waite1013 · Apr 02, 2016 at 04:56 AM · c#cameratop down shooter

Top-down multiplayer camera follow

So I am currently working on a top down shooter game, and am able to get the camera to follow a single player top down character. But Im not sure how to set up the camera so that i follow the player. Note that I cant just make the camera a child of the player object as it will cause the character to spin out of control. So how would I be able to make the characters have a camera follow them from above like Dead Frontier AND be able to have each player have their own camera?

Comment
Add comment · Show 3
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 Cherno · Apr 02, 2016 at 11:08 AM 0
Share

Just set the camera's transform.position to the player's position, with a y offset of course so it hovers above him or her, in Update() on a script that's attached to the camera.

avatar image waite1013 Cherno · Apr 02, 2016 at 03:13 PM 0
Share

By doing that, how would I go about giving each player their own camera? I dont want them sharing a camera. I actually tried to just lock the rotation on the y axis of the camera but it didnt do much. The camera still tried to spin around.

avatar image Cherno waite1013 · Apr 02, 2016 at 03:54 PM 0
Share

I don't know where your problem is. $$anonymous$$ake as many cameras as you want, and have each use a different player transform to follow.

1 Reply

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

Answer by nickostan · Apr 02, 2016 at 03:20 PM

  1. Create a parent "PlayerGOs" gameobject.

  2. Under the gameobject, create your player and a camera.

  3. Do NOT parent the camera to the player object, they should be separate, but following the "PlayerGOs" transform.

  4. Create a script on the camera to have the identical position as the player, but add a y-offest of however much you'd like (10-20 units or so).

Something such as:

     void cameraFollow()
     {
         float charPosX = transform.position.x;
         float charPosZ = transform.position.z;
         float cameraOffset = 18.0f;
 
         viewCamera.transform.position = new Vector3(charPosX, cameraOffset, charPosZ);
 
     }

This script would be placed on the Player gameobject, and reference the camera (doing it publically is likely the easiest). You would also need to call this function every frame in Update or LateUpdate.

 void Update (){
     cameraFollow();
 }

To make sure each player has their own camera in a multiplayer setting, this is a little more complicated, but you'll basically instantiate this PlayerGOs object as the 'player prefab' in your network manager. After that, each script should check if it belongs to the local player, and if not, delete or disable. Such as:

 void Update () {
 
         if (!isLocalPlayer)
         {
             gameObject.SetActive(false); //can probably be done more efficiently so not being called redundantly every frame
             return;
         }


That's how I do it at least, and it works well with no CPU overhead for me.

Cheers. Vranvs

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 waite1013 · Apr 02, 2016 at 03:58 PM 0
Share

Got it, thank you so much! :)

avatar image Whatevermarch · May 24, 2017 at 04:06 PM 0
Share

I follow this and I can't move the player. What components does the "PlayerGOs" object need? Do I have to migrate player's script to PlayerGOs's script? And also, do I need to add NetworkIdentity and NetworkTransform to a camera?

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

3D / Top-Down - Make a script to let the player zoom the camera in and out 0 Answers

Distribute terrain in zones 3 Answers

How can I limit the rotation on the Y axis so the player cant spin the camera 360 in an FPS game? 0 Answers

How do I make a Game Object invisible? 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