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 OscarBrooks · Aug 31, 2013 at 03:11 PM · rigidbodynetworkingmultiplayerserverclient-server

Rigidbody that two players can move/interact with over network?

2 Players. 1 is the Server, 1 is the Client. I need both players to be able to move Rigidbodies owned by the Server using the script below. Both players can move the Rigidbody, but the Server does not observe when the client moves the RigidBody because it is owned by the server. If someone could try and explain clearly what to do e.g. Not just "Use this function, make this RPC call etc..." but explain how I would write the script and what to attach the script(s) to. Thanks.

This is the script I referred to above (I attach this script to the camera of each player):

 private var hittedRigidbody:Rigidbody;
 private var hit:RaycastHit;
 private var distanceToGun:float=3;
 private var catchedObject:boolean=false;
 
 function Start () {
 
 }
 
 
  
 
 function FixedUpdate(){
     if (Input.GetButton("Fire1")){
         castRay();
     }else{
         if (hittedRigidbody!=null){
             releaseObject();
         }
     }
 }
 
 
 function castRay () {
     var direction:Vector3;
     if (hittedRigidbody==null){
         direction=transform.TransformDirection(Vector3.forward);
         if (Physics.Raycast(transform.position,direction,hit,1000)){
             if (hit.rigidbody && hittedRigidbody==null){
                 hittedRigidbody=hit.rigidbody;
                 hittedRigidbody.useGravity=false;
             }
         }
     }else
     if (hittedRigidbody!=null){
         var distance:float=Vector3.Distance(hittedRigidbody.transform.position,transform.position);
         direction=transform.TransformDirection(Vector3.forward);
         
         var myRay:Ray=new Ray(transform.position,direction);
         var _pointVector:Vector3=myRay.GetPoint(distanceToGun);
         
         moveObject(hittedRigidbody,_pointVector);
         
         
         if (distance<=distanceToGun+1){
             catchedObject=true;
         }
     }
 }
 
 
 
 function moveObject(_rigidbody:Rigidbody,_vector:Vector3){
     var finalVector:Vector3=(_vector-_rigidbody.transform.position);
     _rigidbody.transform.Translate(finalVector*Time.deltaTime*10,Space.World);
     
 }
 
 
 function releaseObject(){
     var direction:Vector3=transform.TransformDirection(Vector3.forward);
     if(catchedObject)hittedRigidbody.AddForce(2000*direction);
     hittedRigidbody.useGravity=true;
     hittedRigidbody=null;
     catchedObject=false;
 }
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
Best Answer

Answer by luckruns0ut · Aug 31, 2013 at 04:11 PM

Well what I would do is send a procedure call to the server which basically says "Hey, I want to interact with this object" and the server will perform the force to the object, and reply to the client with a response. This may cause a couple of ms lag, but it will be useful in the long run, because the server will be in complete control of the object.

If you know how to approach it, there is another trick you can do. The client can send that information to the server, like "apply this force at this point" and at the same time the client does that to the ball on his screen. Once the server gets this command, the server will perform this force and send the result to the client, e.g it will send the ball's angular velocity, and position, velocity etc to the client, and it will update on the client's screen if it was incorrect. It could cause a "rubberbanding" effect, but at the same time the client may not actually see the lag as it happens.

I like to have the server in complete control with this sort of thing, which will keep things synchronized.

Just some ideas.

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

17 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

Related Questions

Unity networking tutorial? 6 Answers

Can i save changes to environment in multiplayer game? 1 Answer

Master Server Explanation? 0 Answers

How to test Unity's new networking layer in separate game instances? 0 Answers

Can I create a separate server and use the Unity game objects in it? 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