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 Morderkaine · Oct 29, 2016 at 09:43 PM · networking

Unity Networking, Client cannot affect non-player objects

I have been struggling hard and reading a lot of answers in the forums here but nothing is working. All I am trying to get working is have two players in a game that can each pick up and toss/catch a ball. It is a Vive VR game. Every method ends with either the client cannot touch the ball at all, or can move it but the host doesn't see it move and as soon as the host touches it what the client sees is it snap back to the host.
I have started trying to use [Command] and [ClientRPC] to change and sync the position of the ball. The problem is that I get the error message that the client does not have authority to send a Command to the ball, but the AssignClientAuthority call is just not working apparently. The Command function that should be applying it doesn't even show the Debug.Log statements.

Here is the Balls Script that controls the movement. This works fine on the Host side public class BallScript : NetworkBehaviour {

 [SyncVar] public NetworkInstanceId owner;
 public Rigidbody ball;

 public void DropBall (Vector3 newVelocity, Vector3 newAngVel){
     Debug.Log ("Calling Balls DropBall");
     if (Network.isServer) {
         RpcDropBall (newVelocity, newAngVel);
     } else {
         CmdDropBall (newVelocity, newAngVel);
     }
 }

 public void MoveBall (Vector3 newPos, Quaternion newRot)
 { Debug.Log ("Calling Balls MoveBall");
     if (Network.isServer) {
         Debug.Log ("RPCMove Ball attempt"); 
         RpcMoveBall (newPos, newRot);
     } else {
         Debug.Log ("CMDMove Ball attempt"); 
         CmdMoveBall (newPos, newRot);
     }
 }

 [Command]
 void CmdMoveBall (Vector3 newPos, Quaternion newRot)
 { Debug.Log ("Calling Balls CMDMoveBall");
     if (!Network.isServer) {
         
         ball.transform.position = newPos;
         ball.transform.rotation = newRot;
     }
 }

 [Command]
 void CmdDropBall (Vector3 newVelocity, Vector3 newAngVel)
 { Debug.Log ("Calling Balls CMDDropBall");
     if (!Network.isServer) {
         ball.velocity = newVelocity;
         ball.angularVelocity = newAngVel;
         ball.useGravity = true;
     }
 }

 [ClientRpc]
 void RpcMoveBall (Vector3 newPos, Quaternion newRot ) {
     Debug.Log ("Calling Balls RPCMoveBall");
     if (Network.isServer) {
         ball.transform.position = newPos;
         ball.transform.rotation = newRot;
     }
 
 }

 [ClientRpc]
 void RpcDropBall (Vector3 newVelocity, Vector3 newAngVel) {
     Debug.Log ("Calling Balls RPCDrpBall");
     if (Network.isServer) {
         ball.velocity = newVelocity;
         ball.angularVelocity = newAngVel;
     }
 }

}

And here is the player script that handles the picking up.

public class PickupScript : NetworkBehaviour {

 public GameObject rightObject;
 public SteamVR_TrackedObject rightHand;
 public BallScript heldObject;
 public NetworkInstanceId objNetId;
 private SteamVR_Controller.Device rightController {get { return SteamVR_Controller.Input((int)rightHand.index); } } 
 public NetworkConnection conn;
 public NetworkIdentity myID;

 override public void  OnStartLocalPlayer ()
 {    base.OnStartLocalPlayer();
     objNetId = GetComponent<NetworkIdentity> ().netId;
     myID = GetComponent<NetworkIdentity> ();
      
 }

 // Update is called once per frame
 void Update () {

     if (!heldObject || !isLocalPlayer) {
         return;
     }

     Debug.Log ("HeldObject = " + heldObject.owner + "this is = " + objNetId);

     if (heldObject.owner == objNetId) {
         Debug.Log ("Calling move ball");
         heldObject.MoveBall (rightHand.transform.position, rightHand.transform.rotation);
     } else {
         heldObject = null;
     }

     if ((rightController.GetPressUp (Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger)) && (heldObject.owner == objNetId)) {
         Debug.Log ("Calling drop ball");
         heldObject.DropBall(rightController.velocity, rightController.angularVelocity);
         if (heldObject.owner == objNetId) {
             /// remove authority here, will implement later
             //heldObject.GetComponent<NetworkIdentity> ().RemoveClientAuthority (conn);
         }
         heldObject = null;
     }
 }

 void OnTriggerStay (Collider colinfo){
     if (!isLocalPlayer) {
         return;
     }
     if ((rightController.GetPressDown (Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger)) && (colinfo.tag == "Ball")) {
         Debug.Log ("Grabbing Ball");
         heldObject = colinfo.gameObject.GetComponent<BallScript>() ;
         heldObject.owner = objNetId;
         // Set Authority here!! 
         Debug.Log("calling CmdAssignowner");
         CmdAssignOwner (colinfo.GetComponent<GameObject>());
         Debug.Log ("After CmdAssignOwner call");

     }

 }
  
 [Command]
 public void CmdAssignOwner (GameObject theBall){
     Debug.Log ("Trying to assign authority");
     theBall.GetComponent<NetworkIdentity> ().AssignClientAuthority (connectionToClient);
 }

}

Comment
Add comment · Show 1
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 Morderkaine · Oct 29, 2016 at 09:45 PM 0
Share

The ball itself has a rigidbody, network Identity and network Transform scripts, is set to Local Player Authority and has the first script on it.

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

96 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

Related Questions

How to get OnTriggerEnter working over a network 2 Answers

[UNET] ClientMoveCallback3D Example? 1 Answer

Instantiating over the Network, good way? 1 Answer

Why do I get the error "Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)" when I try to deploy to iOS device. 0 Answers

NetworkServer.Spawn() not being called 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