Object sync

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

dragos2
Posts: 4
Joined: 27 Apr 2010, 19:56

Object sync

Postby dragos2 » 27 Apr 2010, 20:02

Hi,

I'm running smartfox server on my PC (win7) and developing something with unity3d.

I followed a tutorial and I was successful in sync two (or more) players over internet.
To make a long story short, I want to sync a moving object (object is moved by the local player with dragrigidbody) with all players.

Please, if you have any tips on how to do this.

Regards,
Dragos
kidovate
Posts: 13
Joined: 10 Apr 2010, 00:58

Postby kidovate » 28 Apr 2010, 18:36

I too need help with this. And instantiating stuff over the internet.
dragos2
Posts: 4
Joined: 27 Apr 2010, 19:56

Postby dragos2 » 29 Apr 2010, 09:33

Apparently nobody here wants to help on this issue. That's sad.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 29 Apr 2010, 21:15

I'm at a game developers conference so cant help in depth.

If you take a look at the island demo, it has transform sync of the player object + animation sync + does it all via object sending. So that should answer most/all of your questions even with code examples.

Also - please have some patience + try to solve issues by experimentation too yourself. Cant answer every post 2 secs after posting and/or write your code. Just saying.....

/Thomas
kidovate
Posts: 13
Joined: 10 Apr 2010, 00:58

Postby kidovate » 30 Apr 2010, 01:56

Sorry for becoming spoiled with your help Thomas :)

In your demo, you do everything by player id. Is there some sort of way we can do this with regular objects? Any ideas as to how that would work?


Thanks!
Christian Stewart
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 30 Apr 2010, 07:58

Hehe :-)

You can either start down the autoritative server path - meaning that the simulation "master" runs on the server and not the client. This enables you to have a server based "global unique identificator" (usually called GUID) for each object. Which in the island demo is the player id.

You could make a simple GUID system on the server and via that communicate that "the box with GUID 5324 is now being moved".

/T
FlashSpec
Posts: 1
Joined: 30 Apr 2010, 12:09
Contact:

Postby FlashSpec » 30 Apr 2010, 12:22

Maybe this will help: viewtopic.php?t=7249
kidovate
Posts: 13
Joined: 10 Apr 2010, 00:58

Postby kidovate » 02 May 2010, 01:39

Wow. That's my thread :)

Okay, I modified the island demo scripts so that you can synchronize by object name. Be sure to give your objects unique names.

Here are the modified scripts.

The receiver one needs no changes...

Here are the changes.

In the networktransform.cs script change the dosend function to this.

Code: Select all

      public void DoSend(bool useObjectName) {
         SmartFoxClient client = NetworkController.GetClient();
                  
         SFSObject data = new SFSObject();
         if(useObjectName)
            data.Put("_cmd", "t");  //We put _cmd = "t" here to know that this object contains transform sync data.
         else{
            data.Put("_cmd", "to");
            data.Put("objn", obj.name);
         }
         data.Put("x", this.position.x);
         data.Put("y", this.position.y);
         data.Put("z", this.position.z);
         
         data.Put("rx", this.rotation.x);
         data.Put("ry", this.rotation.y);
         data.Put("rz", this.rotation.z);
         data.Put("w", this.rotation.w);
         client.SendObject(data);
      }



In the networkcontroller script make these changes.

In the OnObjectReceived add this -

Code: Select all

         case "to": //"to" means transform sync with object name instead of player id
            SendTransformToRemoteObject(data);
            break;

Further down... add this.

Code: Select all

   private void SendTransformToRemoteObject(SFSObject data){
      GameObject theobject = GameObject.Find(data.GetString("objn"));
      theobject.BroadcastMessage("ReceiveTransform", data);
   }


The next change is this... In the sender script add these changes.

Code: Select all

private bool sendMode = false;


and modify the SendTransform function from the lastState.DoSend() to the following:

Code: Select all

lastState.DoSend(sendWithObjectName);


That's it. Thanks for your GUID # idea Thomas. I probably will have to eventually program that.

Thanks!
Christian.
dragos2
Posts: 4
Joined: 27 Apr 2010, 19:56

Postby dragos2 » 03 May 2010, 11:08

kidovate, thanks for providing a solution for this problem.
I tried modifying the files exactly as you suggested, but I get an error saying "No overload for method 'DoSend' takes '0' arguments.

This is from NetworkTransformSender.cs
dragos2
Posts: 4
Joined: 27 Apr 2010, 19:56

Postby dragos2 » 03 May 2010, 11:17

Hi again,
Don't know where the previous error was coming, but it seems fixed now.

The problem is that I don't know exactly how to use this new scripts (actually the old scripts with additions)

When I run my game it says that the name 'sendWithObjectName' does not exist in the current context.

I've added a Cube to the stage and attached the networktransformsender script to it and I still get the same error message.

Could you please help me with this issue?

Thanks,
Dragos

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 13 guests