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 /
  • Help Room /
avatar image
0
Question by L20GAMES · Apr 05, 2016 at 03:07 AM · cameramultiplayerlayers

Multiplayer Camera Layers

I am having trouble layering the cameras for a multiplayer FPS game. One camera on the player shows the gun and the other camera shows everything else (so the gun doesn't go through walls and what not). My problem is that the gun camera is rendering everyone else's guns on top of the surrounding objects. How do I make it so the camera only renders the gun that the player is holding on top of everything else. I hope that made sense. Thankyou

Comment
Add comment · Show 5
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 SnooksV3 · Jun 11, 2020 at 09:16 PM 0
Share

Did you find a solution for this? The struggle is real right now.

avatar image L20GAMES SnooksV3 · Jun 12, 2020 at 12:54 AM 0
Share

It was 4 years ago now, I'm trying my hardest to work out what I did but I am really unsure how I ended up fixing it.

I'm not sure if this is the solution as I haven't done any multiplayer in years but my guess would be:

  • Start with all guns on the normal camera

  • When the player is spawned in switch the gun to the "gun camera" This should make the gun only move to the gun camera for the local client and not everyone else on the server, thus fixing the problem.

I'm not sure if this will work but it's my best guess. I hope you find a solution soon.

avatar image SnooksV3 · Jun 12, 2020 at 02:01 AM 0
Share

Thanks for responding! I don't expect you to but hoping one day someone can answer it.

I'm closer to understanding from this video here:

https://www.youtube.com/watch?v=QhKlvdixOX0

This video explains it but it's still going over my head.

 gameObject.layer = Layer$$anonymous$$ask.NameToLayer("YourLayerName");

I understand that this sets the layer if you load it after a player has spawned, but wouldn't that just be the same thing? If every spawned player had this piece of code run when they spawned, the result would be the same...

avatar image L20GAMES SnooksV3 · Jun 13, 2020 at 04:54 AM 0
Share

I'll try explain this with my limited knowledge but from my understanding the code

  gameObject.layer = Layer$$anonymous$$ask.NameToLayer("YourLayerName");


will only run on the client not the server as it hasn't been specified to, so the following things will happen:

  1. All guns start rendered by the main camera (as they are on the main layer)

  2. Players spawn in and see every gun rendered by the main camera, this will mean they are not rendered in front of everything else (like the problem your having), but causes them to go through objects in the first person view.

  3. You then switch, through code, the layer that the Player's (and only the local player, not every player) gun is on. Now the gun is rendered only by a "gun camera", stopping them from clipping through objects in first person.

  4. So now every gun in still being rendered by the main camera, except the local player's gun.

  5. Because the code is run locally it doesn't effect all the other players guns and will only change the local players gun. This happens for every local player and thus should fix your problem.

If you still need help, let me know

avatar image SnooksV3 · Jun 13, 2020 at 10:34 PM 0
Share

Thank you! That was the answer I was looking for. The video did not mention that properly. Appreciate it!

0 Replies

· Add your reply
  • Sort: 

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

87 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

Related Questions

PUN fps help 0 Answers

Animated Sprites blocked by Canvas 1 Answer

MLAPI - Lost with instantiate 1 Answer

How can I change the viewport rect of two active cameras at runtime? - Splitscreen Multiplayer 1 Answer

Both Game & Scean Tabs are showing objects exactly right > But Play dose not show the same.... Why ??? 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