Author Topic: Best way to set Transform ref  (Read 2602 times)

choarrim

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 5
    • View Profile
Best way to set Transform ref
« on: July 27, 2016, 12:39:04 AM »
Hi,

I am currently working on my game which is a turn based game and on that players turn he clicks a button to TNManager.Instantiate a Transform.

The Transform then follows the created user's mouse cursor and when the user clicks on the board the user can then start to rotate this on fixed angles. All this is working but I am very confused on how one should think to make sure the transform gets properly placed and rotated on both connected users. Since the instantiate uses a static method and the TNManager is void, how can I get a hold of the created transform and store it in a Transform variable?

Hope I explained enough :)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Best way to set Transform ref
« Reply #1 on: July 27, 2016, 03:19:59 PM »
You don't. Have a script on the object to synchronise it over the network. Such as test to see if the current player is the object owner, and if so, send an RFC to the other player telling them the transform's position. Then the RFC on the client sets its local copy of the object to the values passed.

The Autosync (?) script in Tnet might be good enough for a turn based game.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Best way to set Transform ref
« Reply #2 on: July 27, 2016, 03:21:18 PM »
Maybe I'm missing something in your explanation, but wouldn't it be easier to sync the rotation of the board? You could even optimize it a lot because you said it rotates at fixed angles, meaning there's finite possibilities (if it's under 255 possibilities that's 1 byte per rotate instead of 4 or 12).

If what you want is to sync the movement of the cursor as well, then treat that just as you would the board. Don't try sending the logic over the network, just send the outcome (position and rotation).

I don't know how familiar you are with TNet, so I'll go more in-depth (you can ignore this if you're already familiar):
1. Create a board prefab
2. Create a cursor prefab
3. On both prefabs, add the TNAutoSync component and click the "Add a new synchronized property" button twice. This should add its transform twice, with a box to the right containing <None>. Click that box and select position for the first one and rotation for the second one.

Now whenever you instantiate those prefabs (using TNManager), their positions and rotations will be synced across the network. You can take a look at how the TNAutoSync script works and build your own syncing script.