Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 lhk · May 08, 2011 at 01:44 PM · cameranetworkingrenderinglayers

Network restrictive rendering

Hi, now I have an additional problem. I would like to set up a player prefab with an animated playermesh and a weaponmesh. The prefab contains a camera that should render only the weapon but not the player's body. Now let's look what happens if someone plays the game:

  • He starts the game
  • He chooses "start server" in the GUI implemented by a pretty much standard script like "connect.js"
  • A player-prefab is network.instantiated on his machine
  • He can now walk, jump, shoot and interact with the scene
  • A second person starts the game and connects to this server
  • Now the camera of our first person should render the enemies body but not its own. Additionally it would be nice, if the camera of player 1 wouldn't render the weapon of player 2

The problem:

Can I change the layer of a GameObject during runtime ? If this is possible I could make a check for networkView.isMine and change the layer individually on each machine.

Is there something like camera.Ignore(GameObject) ? If there's something like this, how can I still render the children of the ignored GameObject ?

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
1
Best Answer

Answer by Cyb3rManiak · May 08, 2011 at 02:14 PM

You can most definitely change the layer during runtime... From the scripting reference:

// Put the game object in the ignore raycast layer
gameObject.layer = 2;

If you want to continue with your way, you can setup the layers (for example) as

MyWeapon, MyPlayer, OtherWeapons, OtherPlayers.

Then, you can use Camera.cullingMask on your camera to decide what it renders, and what not. You can either edit your prefab of the player (change the camera's cullingMask in the inspector) Or you can have a variable in your spawn script:

public var localPlayerSees: LayerMask;

If it's public you can edit it in the inspector, just like you edit the cullingMask.

When you instantiate your local player, just assign:

remotePlayerCamera.cullingMask = localPlayerSees;

When you instantiate a remote player, move the relevant game objects on the instantiated player to the appropriate layers (OtherPlayers, OtherWeapons). The camera will do the rest.

Alternatively, you can also create two prefabs - one for a local player, one for a remote one.

BTW, just out of curiosity - why would you not want to display other player's weapons? (Unless the weapon is a heavy object and you want to replace it with some low poly object)

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 lhk · May 08, 2011 at 08:05 PM 0
Share

I don't know how to turn my weapon object correctly. So I have two objects: The weapon from which shots are fired. It's parented to the camera and moves just like in any other fps. $$anonymous$$oreover I have the player oject. It's animated to walk and jump. However I don't know how I can correctly turn the player's hands in the direction the camera is facing. Therefore I render just the playermesh and not the weapon for other machines and the other way round on the local machine. To the player it looks like the shots are instantiated in mid-air but that's better than a weapon not connected to the player.

avatar image lhk · May 08, 2011 at 08:07 PM 0
Share

If you know how to turn the player's upper body up and down with a script, I would appreciate it very much, if you could help me. Up to know everybody is fighting unarmed persons that shoot from nowhere and can't look up and down.

avatar image Cyb3rManiak · May 09, 2011 at 08:56 AM 0
Share

I could start and explain exactly how to do it, but I think it's much more productive if you just change the "Head Look Controller" that Unity have on their resources section (http://unity3d.com/support/resources/unity-extensions/head-look-controller). It's meant to turn the head towards something interactively, but I think it can easily be changed to effect the torso if necessary :)

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

No one has followed this question yet.

Related Questions

Camera rendering help. 1 Answer

How to apply target, while created at runtime? 1 Answer

camera layer issue, multiplayer. 1 Answer

Post processing with multiple camera 1 Answer

Camera with background hides game 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