• 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 Stros · Mar 23, 2016 at 04:47 PM · collisionnetworkingplayernetworknetworkplayer

Network two players collision

Hi, i´m working on network game like agar.io, network works fine with using unet but i have problem ... if i connect two player i spawns same players - Player(Clone) and i have no idea how can i do collision between them. I need if one of them will be bigger then second he can eats him.

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 Arshoon · Mar 23, 2016 at 05:01 PM

Collision works the same in multiplayer as it does in single-player. Both player clones will have a Collider on them (most likely a capsule). How you set who is bigger is a problem you will have to tackle. Remember that the actual "eating" should be decided by the server with a Command.

Read this for Colliders: http://docs.unity3d.com/Manual/CollidersOverview.html

This for a sample of a Command: http://unity3d.com/learn/tutorials/topics/multiplayer-networking/adding-multiplayer-shooting?playlist=29690

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 Stros · Mar 24, 2016 at 07:12 PM 0
Share

Yes, but i want copare who is bigger at the moment because they are increasing by eating food. I need distinguish one clone by second clone.

avatar image srylain Stros · Mar 24, 2016 at 07:31 PM 0
Share

Do you not keep track of what size players are at? It should be trivial.

Use a Command that is sent when players touch, which includes the netId of the players who touched. On the server, figure out who's smaller and then reward the bigger player and kill the smaller player with RPCs.

avatar image Stros srylain · Mar 25, 2016 at 04:34 PM 0
Share

I have this script, how can i do what you told me please ?

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 
 public class AgarScript : NetworkBehaviour {
     public Rigidbody2D PlayerRigid;
     public float PlusScale;
     public float PlusScale1;
     public GameObject Player;
     //public float speed1;
 
     public Camera myCamera;
     public float speed ;
     private Vector3 mouselocation;
     private Vector3 direction;
 
 
 
     //private float movex = 0f;
     //private float movey = 0f;
 
 
 
 
     // Use this for initialization
     void Start () {
         if (!myCamera)
         {
             myCamera = Camera.main ;
         }
     }
 
     void Awake() {
         Application.targetFrameRate = 300;
     }
 
         
         
 
     
     // Update is called once per frame
 
     void Update () {
 
         if (!isLocalPlayer)
         {
             return;
         }
         //$$anonymous$$amaera sleduje hráče
         Camera.main.transform.position = new Vector3 (transform.position.x, transform.position.y, Camera.main.transform.position.z);
 
         //Pohyb myší
         mouselocation = Input.mousePosition ;
         mouselocation.z = 10 ;
         direction = myCamera.ScreenToWorldPoint( mouselocation ) ;
         transform.position = Vector3.$$anonymous$$oveTowards(transform.position , direction , speed * Time.deltaTime ) ;
 
         ////Pohyb šipkama
         ////var move = new Vector3 (Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical"), 0);
         ////transform.position += move * speed1 * Time.deltaTime;
 
 
             //Pohyb šipkama
             //movex = Input.GetAxis ("Horizontal");
             //movey = Input.GetAxis ("Vertical");
             //PlayerRigid.velocity = new Vector2 (movex * speed1, movey * speed1);
 
 
 
 
 
         if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Escape))
             Application.Quit();
     
     }
     //$$anonymous$$olize
     void OnTriggerEnter2D(Collider2D col){
         if(col.gameObject.tag == "Food"){
             Destroy(col.gameObject);
             ScalePlus();
         }
 
         //if(col.gameObject.tag == "Hrac"){
         //        Destroy (col.gameObject);
         //        ScalePlus1 ();
             
         //}
 
         if(col.gameObject.tag == "Limit"){
             print ("asd");
 
 
         }
 
             
     }
 
 
     void ScalePlus(){
         gameObject.transform.localScale = new Vector3(transform.localScale.x+PlusScale,transform.localScale.y+PlusScale,transform.localScale.z);
     }
     void ScalePlus1(){
         gameObject.transform.localScale = new Vector3(transform.localScale.x+PlusScale1,transform.localScale.y+PlusScale1,transform.localScale.z);
     }
 
 
 }

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Multiplayer|3dText PlayerName 1 Answer

Network Player prefab in my scene, how to automatically delete it on all clients/server when scene loaded? 0 Answers

Adding children to player during runtime in a multiplayer game with NetworkTransformChild Component 1 Answer

How to make network player lose health after being hit by rigidbody? 1 Answer

Does NetworkPlayer.guid stay the same for the entire lenght of the networking session? 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