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 /
avatar image
0
Question by mollaplump · Jul 08, 2016 at 09:56 AM · unity 5networking

Help with syncing non-player game objects with other players using UNet please?

Hey! So I made this game where you have a given time to spawn in a load of blocks (by hitting an in-game button), picking up those blocks and placing them on top of one another to build a tower. I then started working on the multiplayer aspect of the game. I have successfully synced the players, however the issue comes with the blocks themselves. When a player runs into a button (it's a weird system, I know) a block spawns near the button. The player then runs into the block and the block becomes a child of the player and so it moves with them (some other transformations take place so the block can be seen by the player). The spawning and the picking up of the block can be seen by other players - no problem. However, by pressing 'E' the block is dropped, and as soon as it comes into contact with the ground or another block it freezes its position and rotation and gravity is disabled and it becomes part of the tower. The dropping of the block is, oh so sadly :(, not visible to other players, as far as other players are concerned the player that picked up the block is still carrying the block, regardless as to whether it has been placed or not. Below I have attached the relevant scripts and would love some advice from you guys as to how to proceed in syncing this menace of a GameObject. (Please go easy on me, the code is a mess, this is my first successful-ish attempt at a game so... yeah XD)

Pickup script - The picking up and dropping of the blocks by the player are contained here.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 
 public class Pickup : NetworkBehaviour {
 
 GameObject Player1;
 GameObject ToBeChild;
 public bool SomethingCarried;
 public bool SomethingDropping;
 
 
 
 void Start()
 {
 Player1 = GameObject.Find("FPSController(Clone)");
 }
 
 
 
 public void OnCollisionEnter(Collision pickingup)
 {
 if (pickingup.gameObject.tag == ("Building Block"))
 {
 ToBeChild = pickingup.gameObject;
 carrying();
 pickingup.gameObject.GetComponent<Rigidbody>().useGravity = false;
 
 Debug.Log("Pickup Attempt");
 } else
 {
 //nothing
 }
 }
 
 public void dropping()
 { 
 Debug.Log("Drop Attempt");
 SomethingDropping = true;
 SomethingCarried = false;
 ToBeChild.transform.parent = null;
 Debug.Log("Dropped!");
 ToBeChild.gameObject.GetComponent<Rigidbody>().useGravity = true;
 ToBeChild.gameObject.GetComponent<Rigidbody>().freezeRotation = true;
 ToBeChild.gameObject.GetComponent<Collider>().enabled = true;
 ToBeChild.gameObject.tag = "Placed";
 if(ToBeChild.gameObject.tag == ("Placed"))
 {
 SomethingDropping = false;
 }
 ToBeChild = null;
 }
 
 public void carrying()
 {
 ToBeChild.transform.parent = Player1.transform;
 SomethingCarried = true;
 ToBeChild.gameObject.tag = "Carrying";
 Debug.Log("Carrying!");
 }
 
 
 public void Update()
 {
 if (Input.GetKeyDown(KeyCode.E))
 {
 dropping();
 }
 if(SomethingCarried == true)
 {
 ToBeChild.gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
 ToBeChild.gameObject.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
 ToBeChild.gameObject.GetComponent<Rigidbody>().rotation = Quaternion.identity;
 ToBeChild.gameObject.transform.localPosition = Vector3.up / 2;
 ToBeChild.gameObject.transform.localPosition = Vector3.forward * 2;
 ToBeChild.gameObject.GetComponent<Collider>().enabled = false;
 }
 if (Input.GetKeyDown(KeyCode.LeftControl))
 {
 SomethingCarried = false;
 ToBeChild.gameObject.GetComponent<Collider>().enabled = true;
 ToBeChild.transform.parent = null;
 ToBeChild.gameObject.GetComponent<Rigidbody>().drag = 1;
 ToBeChild.gameObject.GetComponent<Rigidbody>().useGravity = true;
 ToBeChild.gameObject.tag = "Building Block";
 }
 
 }
 
 }

Ground Collision script - The sticking of the dropped block to other blocks is done here.

 using UnityEngine;
 using System.Collections;
 
 
 public class GroundCollision : MonoBehaviour {
 
 public GameObject ground;
 
 void Start () {
 gameObject.GetComponent<GroundCollision>().enabled = false;
 }
 
 public void OnCollisionEnter(Collision groundcollision)
 {
 gameObject.GetComponent<GroundCollision>().enabled = true;
 ground = groundcollision.gameObject;
 }
 
 void Update () {
 if (gameObject.tag == ("Placed"))
 {
 checkgroundorblock();
 } else if (gameObject.tag != ("Placed")){
 end();
 }
 }
 
 void checkgroundorblock()
 {
 if(ground != GameObject.Find("Player 1"))
 {
 gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
 gameObject.GetComponent<Rigidbody>().isKinematic = true;
 Physics.IgnoreCollision(ground.GetComponent<Collider>(), GetComponent<Collider>());
 ground = null;
 end();
 }
 if (ground != GameObject.Find("Player 2"))
 {
 gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
 gameObject.GetComponent<Rigidbody>().isKinematic = true;
 Physics.IgnoreCollision(ground.GetComponent<Collider>(), GetComponent<Collider>());
 ground = null;
 end();
 }
 if (ground != GameObject.Find("Player 3"))
 {
 gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
 gameObject.GetComponent<Rigidbody>().isKinematic = true;
 Physics.IgnoreCollision(ground.GetComponent<Collider>(), GetComponent<Collider>());
 ground = null;
 end();
 }
 if (ground != GameObject.Find("Player 4"))
 {
 gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
 gameObject.GetComponent<Rigidbody>().isKinematic = true;
 Physics.IgnoreCollision(ground.GetComponent<Collider>(), GetComponent<Collider>());
 ground = null;
 end();
 }
 }
 
 void end()
 {
 Start();
 }
 }

Thanks in advance for any help!

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to use NetworkManager.ServerChangeScene ? 1 Answer

Spaw dynamic (unregistered) object on network (UNET) 0 Answers

how do you send commands from objects that dont have "Authortiy" unet 1 Answer

can't switching between weapons in multiplayer game? 0 Answers

Network Transport Layer API does not work with iOS to PC? 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