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 Casper 1 · Jan 25, 2012 at 09:42 PM · multiplayerplayernetworkserverclient

Player falls through plane/floor (Multiplayer)

Hello

I created two projects: Client and Server

On my server and client I have a "Player" prefab. This prefab has a network view on it as well as a rigidbody.

My server runs the following code:

When I click on a button:

 Network.InitializeServer(10, 25000, false);

When a player disconnects and I want to remove him:

 void OnPlayerDisconnected(NetworkPlayer player)
 {
     Network.RemoveRPCs(player);
     Network.DestroyPlayerObjects(player);
 }

When a player connects:

 void OnPlayerConnected(NetworkPlayer player)
 {
     Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
 }

My question is do I have to create the same level for the player on my server as well as on my client?

My client has a simple "Plane" which he falls on when he connects, but if I dont create the same "Plane" on my server my "Player" falls through the plane on the client side.

It seems highly inconvenient to do it this way. Also is this the correct way? Im unsure about where to instantiate gameobjects (Server or client)?

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 syclamoth · Jan 25, 2012 at 11:17 PM

If you are using 'Network.Instantiate' you should always use it on the client that should be in 'control' of that object. If you instantiate it from the server-side, the server ends up having 'control' over every object! If you want the server to have control over when the players get instantiated, you can manage it with a player RPC. Given that every player has an object assigned to them that can receive RPCs, you can use

 networkView.RPC("SpawnPlayer", networkView.owner);

and then have a procedure called 'SpawnPlayer' that does the network Instantiation.

Another thing- I don't see what's so inconvenient about the server having to create the same level as all the clients. It makes sense for the server to know as much as possible about the environment, even if the server isn't also another player! And if the server is another player, then you don't need to worry about the environment thing at all, because naturally they will be in the same level as everyone else.

Comment
Add comment · Show 4 · 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 Casper 1 · Jan 26, 2012 at 12:03 AM 0
Share

Thanks for the answer.

I see what you mean about it, but in my head its double the work, having a level where you edit one thing on the client side then having to edit the same thing on the server side as well.

But I guess I will just design the level/scene first and export it to my client after :)

By the way how do I remove a "Player (Clone)" gameobject from the network?

I know about "Network.Destroy" and I would guess it has to be done when at OnPlayerDisconnected, but I cant seem to wrap my head around it (Nor get it to work :-P)

avatar image syclamoth · Jan 26, 2012 at 12:07 AM 1
Share

I don't follow- it's no more work, because the client and the server use the same scene, in the same project!

If you want to remove a player's owned objects, you can use

 Network.DestroyPlayerObjects(networkPlayer);

from the server to destroy all objects whose owners are that player. Use it from OnPlayerDisconnected. The reason you can't get it working, is probably the same problem as with the instantiation- you need the players to 'own' their own characters.

avatar image Casper 1 · Jan 26, 2012 at 12:17 AM 0
Share

Again thank you, I appreciate you taking your time to answer :)

I can follow you in the sense if its the same project both running the client and the server.

But in my case I have a stand alone server (Project) accepting clients.

I might just have to integrate the server into the client

$$anonymous$$aybe i'm just misunderstanding this.

avatar image syclamoth · Jan 26, 2012 at 12:24 AM 2
Share

Yeah, that's what I'm saying. I see no reason not to have the server and client in the same project. In fact, I see separating them as creating work for yourself for no good reason. The whole 'client-server separation thing' makes sense on a low level, but Unity as a whole operates on a much higher level than that. You should be concentrating on desired behaviour, not how that behaviour occurs.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Server and Network no communication 1 Answer

Do i need to have 2 seperate apps communicating for server/client relationship? 2 Answers

How to hide a started/full server 0 Answers

What is the CCU of the default Unity Networking? 1 Answer

Multiplayer server-client setup 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