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 robbel · Oct 13, 2017 at 10:14 PM · networkingtutoriallearningco-op

Learning resource for networking?

Hey,

i did the tutorial on networking. Im now looking for more as the one tutorial is insufficient. it says we'll learn about interpolation and advanced techniques in an other topic, but i dont think it exists.

when googling i could only find others having the same trouble, most questions without an accepted answer.

where should i look?

in detail, i am trying to make a simple coop 2d shooter, just to learn networking. one client is acting as server. when shooting on the non-server-client, the bullet spawns with a noticable delay (even when executing on the same machine). i want the client to just spawn its own bullet localy, then tell the server about it. i dont care about cheating.

guess thats kind of a common objective, i dont get why there seems to be no resource about this.

help :(

edit: i dont need a specific answer here; i am mostly looking for links to advanced networking tutorials.

edit2: i asked about this, phrased differently, some time ago. got no answer. cant find resource. i love unity, but networking is realy hard and i need additional advice!

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
0

Answer by robbel · Oct 15, 2017 at 01:43 PM

Okay,

so i couldnt find any resource on this, but i managed to get the visual part "right".

Spoiler: solution is dirty (the bad kind).

I support 2 players only. One player is acting as host, so ill call him just that. The other player i will call client (tho technically both are clients ait?).

When the host shoots, everythings fine. Just spawn the bullet acording to the networking tutorial. However, when the client fires, i localy spawn a bullet, and then tell the server to spawn an equal bullet (wich i call clone henceforth). I attached a script to the bullet that disables the renderer, network transform and circular collider of the bullet when spawned on the client and is a clone.

just look at this mess:

 /* player controller */
 void Update()
         {
             if (!isLocalPlayer)
             {
                 return;
             }
     
             //(some code to move the player and set direction)
     
             if (Input.GetKeyDown(KeyCode.Space))
             {
                 Fire(direction);
             }
         }
     
         void Fire (Vector2 dir)
         {
             // spawn bullet weather client or host
             var bullet = SpawnBullet(dir);
     
             if (isServer)
             {
                 // case 1: Host firing
                 // just spawn the bullet
     
                 NetworkServer.Spawn(bullet);
             }
             else
             {
                 // case 2: Client firing
                 // command server to spawn a copy of the bullet, but disable most of it when its replicated on the client that shot. 
     
                 CmdClone(dir);
             }
         }
     
         [Command]
         void CmdClone(Vector2 dir)
         {
             var clone = SpawnBullet(dir);
     
             clone.GetComponent<ClientSpawn>().isClone = true;
     
             NetworkServer.Spawn(clone);
         }
     
         GameObject SpawnBullet(Vector2 dir)
         {
             var bullet = (GameObject)Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);
     
             bullet.GetComponent<Bullet>().ownerId = id.get();
             bullet.GetComponent<Rigidbody2D>().velocity = dir * 15;
     
             Destroy(bullet, 2.0f);
     
             return bullet;
         }
 
 
 /* script attached to bullet */
 
     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     using UnityEngine.Networking;
     
     public class ClientSpawn : NetworkBehaviour
     {
     
         [SyncVar]
         public bool isClone = false;
     
         void Start()
         {
             if (isClone && !isServer)
             {
                 GetComponent<SpriteRenderer>().enabled = false;
                 GetComponent<NetworkTransform>().enabled = false;
                 GetComponent<CircleCollider2D>().enabled = false;
             }
         }
     
     }
 

But will it blend?

Im curious if i am able to get the destruction of the bullet and its clone synced properly, and so on.

I Obviously still need help, and if this continues, i will develope some mental disorder, maybe multiple.

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

155 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 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

Detect specific game object with raycast and show UI when hit 2 Answers

Is the customizable character tutorial still out there somewhere? 2 Answers

Unity 3D textbook / ebook 0 Answers

Multiplayer FPS version of unity networking tutorial? Using rigidbodies- see project link 0 Answers

Roll a ball Movement. 0 Answers


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