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 Mint92 · Apr 27, 2014 at 01:23 PM · collisionnetworkrpc

Updating collision on both server and client

alt text

How does collision work on network. every time i seem to fire on the server side it destroys the cube that ive targeted, but over on the client side it says ive destroyed the ones in the middle.

this is my script for destroy cube using UnityEngine; using System.Collections;

 public class DestroyCube: MonoBehaviour 
 {
     
     private Game game;
     
     void Start () 
     {
         game = (Game)GameObject.Find("GameManager").GetComponent("Game");
     }
     
     void OnTriggerEnter(Collider other)
     {
         if (Network.peerType == NetworkPeerType.Server)
         {                
             if (other.tag == "Bullet")
             {
                 string shipName = ((Bullet)other.GetComponent("Bullet")).getFiredBy();
                 
                 Debug.Log("Bullet fired by " + shipName + " has hit " + gameObject.name);
                 
                 GameObject ship = GameObject.Find(shipName);
             
                 // remove the bullet from the bullet list
                 game.removeBullet(other.gameObject);
                 
                 // tell all clients to destroy the bullet
                 game.getNetworkView().RPC("DestroyBullet", RPCMode.Others, other.gameObject.name);
 
                 // destroy bullet on server
                 Destroy(other.gameObject);
                 
                 // tell all clients to destroy the cube
                 game.getNetworkView().RPC("DestroyCube", RPCMode.Others, gameObject.name);
                 
                 // destroy cube on server
                 Destroy(gameObject);
             }
         }        
     }
 }

which is then called from a RPC Function from another script

[RPC] public void DestroyCube(string cubeName) { GameObject cube = GameObject.Find("DestroyableCube");

         if (cube != null) 
         {
             Debug.Log("Destroying Cube " + cubeName);
             DestroyCube cubeScript = (DestroyCube)cube.GetComponent("DestroyCube");
             Destroy(cube);
         }
     }        
tank6.png (32.0 kB)
Comment
Add comment · Show 2
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 Mint92 · Apr 28, 2014 at 11:30 AM 0
Share

Do i need to update this somehow ?

avatar image Mint92 · Apr 28, 2014 at 11:44 AM 0
Share

would i have to do something similar in the way my bullets get removed

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Game : $$anonymous$$onoBehaviour 
 {
     public bool running;
     
     public List<GameObject> bullets;
     public List<GameObject> newBullets;
     public List<GameObject> cubes;
     public List<GameObject> newCubes;
 
     public GameObject DestroyableCube;
     
     private Rect bulletCountPos, resetGamePos, startGamePos, gameRunningPos;
         
     // Use this for initialization
     void Start () 
     {
         resetGamePos = new Rect(10, 70, 150, 20);        
         startGamePos = new Rect(10, 90, 150, 20);
         
         bullets = new List<GameObject>();
         newBullets = new List<GameObject>();
         
         bulletCountPos = new Rect(Screen.width - 200, 10, 200, 20);            
         gameRunningPos = new Rect(Screen.width - 200, 30, 200, 20);            
     }
     
     
     void Update () 
     {
         if (running)
         {
             if (Network.peerType == NetworkPeerType.Server)
             {
                 //Debug.Log("Updating bullet list");
                 
                 Bullet bulletScript;
                 newBullets = new List<GameObject>(bullets);
     
                 bullets.Clear();
                 
                 // check all local bullet flight times
                 // Network.Destroy any over time
                 foreach(GameObject bullet in newBullets)
                 {
                     // check if bullet still exists (because the collision trigger messages can run during this update loop)
                     if (bullet == null) continue;
                     
                     bulletScript = (Bullet)bullet.GetComponent("Bullet");
                     
                     if (bulletScript.currentFlightTime < bulletScript.maxFlightTime)
                     {
                         bullets.Add(bullet);
                     }
                     else
                     {
                         // tell all clients to destroy the bullet
                         Debug.Log("Ordering clients to remove " + bullet.name);
                         networkView.RPC("DestroyBullet", RPC$$anonymous$$ode.Others, bullet.name);
 
                         // destroy local bullet on server
                         Destroy(bullet);
                     }
                 }                
                                 
                 // clear the newBullets list
                 newBullets.Clear();
             }
         }        
     }
     

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mint92 · Apr 28, 2014 at 01:41 PM

Silly mistake, i needed to give each cube there own ID number. works fine now

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

20 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

Related Questions

View ID AllocatedID: X not found during lookup. 1 Answer

RPC call problem : local variable unvaluated ? 1 Answer

Why isn't my RPC shooting code working? 0 Answers

RPC Call to Another GameObject's Function? 1 Answer

Networking Error! 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