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

People who like this

0 Show 0
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

  • Sort: 
avatar image

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

People who like this

0 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;
         }
         //Kamaera 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.MoveTowards(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.GetKeyDown (KeyCode.Escape))
             Application.Quit();
     
     }
     //Kolize
     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);
     }
 
 
 }

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

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

Getting Reference to Player Objects at Network Game 1 Answer

Don't destroy player after disconnecting or calling ClientScene.RemovePlayer() 1 Answer

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

Deleting a player over the network 1 Answer

Help with getting script of another player 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