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
Object sync
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
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
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
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
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
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
Maybe this will help: viewtopic.php?t=7249
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.
In the networkcontroller script make these changes.
In the OnObjectReceived add this -
Further down... add this.
The next change is this... In the sender script add these changes.
and modify the SendTransform function from the lastState.DoSend() to the following:
That's it. Thanks for your GUID # idea Thomas. I probably will have to eventually program that.
Thanks!
Christian.
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.
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
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 17 guests