Some questions from a newbie !! :-)

Hello !! :-)
Totally new to Photon, TrueSync and all the rest of the family.
Trying to investigate and making prototypes to see if I can get my head around it and if Photon serves the purposes of what I should develop.
I'm using Unity.
What I'm trying to do is a simulation of a ball bouncing on walls using TrueSync (that possibly I will turn on a pong demo). I'm a control freak, so, I'm trying to manage manually all the connections. What I did is a state machine that will eventually ends up connecting using Photon. When all the players are available and the room is full, I'm triggering a RPC that will instantiate the TrueSyncManager starting the system (I don't really like the loading scene approach). The OnSyncedStart received on my TrueSync controller, will then trigger the start of the synced game (synced instantiation of entities and all sort of stuff). From this moment on, nothing else apart the TruSync physics is running.

Here are the questions:
1) at the beginning I tried to have the walls in the scene (all instances on your TSBox primitive) when the TrueSyncManager is still not instantiated. When the manager is instantiated by the RPC, the wall positions are reset to TSVector.zero. Is there any specific reason why? Apparently the only thing that fixes this is to instantiate the walls (using SyncedInstatiate) after the TrueSyncManager is instantiated in the scene.
2) trying to make a bouncy ball, I created a TSMaterial with 0 friction and 1 restitution. This material is on a GameObject that is in the scene and I'm sharing the same materials with all the TSColliders it needs to be on (walls and ball). Balls and walls are instantiated when all the players are connected and synced and then I do assign the material to everything that needs it. From the Inspector I can see that the martial is correctly referenced. Unfortunately, once the game runs, the ball collides with a wall but it doesn't bounce, instead it will align itself to the wall surface and keeps moving along it. It will eventually stop dead in a corner. What am I doing wrong?
3) I tried to implement a UI button that should trigger a reset function on the ball so that the ball will respawn from the center when stop dead. What I did is to try to simulate a synced input so to have the same effect on all the connected players. This is probably when I'm messing up too much; let me explain what I am doing. The ball class overrides the OnSyncedInput method that will set the a boolean when the UI button is pressed. Then, in the OnSyncedUpdate, if the GetBool is true, I will respawn the ball. The ball is spawned in the scene when the TrueSyncManager will start the game. Let me show you the code:

public override void OnSyncedUpdate() {
if(TrueSyncInput.GetBool(INPUT_RESPAWN)) {
Reset();
Spawn();
}
}

public override void OnSyncedInput() {
if(m_respawnRequested) {
m_respawnRequested = false;
TrueSyncInput.SetBool(INPUT_RESPAWN, true);
}
}

At the beginning I was getting the "You can't access an input in a TrueSyncBehaviour that has no player owner." warning message because I was not setting manually any owner (nothing is instantiated by the TrueSyncManager, I'm doing it manually). What I'm doing now is to use this lines of code:

m_ball = TrueSyncManager.SyncedInstantiate(m_ballPrefab, TSVector.zero, TSQuaternion.identity).GetComponent();

m_ball.owner = TrueSyncManager.LocalPlayer;

This is because I would like all the players to be able to press the button and the action to be reflected in all of them. As you can guess, the result is that the ball is respawning but only locally. Can you please point me in the right direction?

Wow... that is massive as first post.
I hope is not too much !! :-P

Thank you for your kind reply.

Comments

  • Hello @Eugenio_IT, nice post, lets try to discuss each point:
    1) For the wall did you use a base prefab? If so we have a weird bug on that, you should click on TSTransform component of each wall and reset it. If not, try to reproduce some of demos, most of them have walls set at the beginning.

    2) Humm, unfortunately I don't know by this description, I advise you to create a simple scene with a ball and a ground, and test it offline with TrueSync, so you can tweak params to try the bounce effect. We have some similar behaviour on our 2D soccer demo, there is a bouncing ball there.

    3) Well, you need a player because a global input storage could be set by multiple players in a same key with different values for the same tick, which will lead to a non deterministic simulation. But you have an option, you can read the value from other players, there is an overloaded method for each GetXYZ.
  • Hello @JeffersonHenrique and thanks for your reply. So, I did more tests and here are the results.


    1) For the wall did you use a base prefab? If so we have a weird bug on that, you should click on TSTransform component of each wall and reset it. If not, try to reproduce some of demos, most of them have walls set at the beginning.

    I tried to reset the TSTrasform on my prefab but if I don't instantiate the walls at runtime their position will be reset.
    I did expose the Position variable in the inspector so to check if it actually has the initial values and if it's initialized and it is. During the connection to the server something goes wrong and the Unity Transform is reset to Vector3.zero whilst the TSTransform still does have different value. I think that TrueSync is counting the arena to be out of sync and not update it any more.


    2) Humm, unfortunately I don't know by this description, I advise you to create a simple scene with a ball and a ground, and test it offline with TrueSync, so you can tweak params to try the bounce effect. We have some similar behaviour on our 2D soccer demo, there is a bouncing ball there.

    Right... I tried to mess around with the values of the TSMaterial but I was not able to get anywhere. I'll try to create an example project and send it to you so you can take a look and let me know !! :wink:


    3) Well, you need a player because a global input storage could be set by multiple players in a same key with different values for the same tick, which will lead to a non deterministic simulation. But you have an option, you can read the value from other players, there is an overloaded method for each GetXYZ.

    Thanks, that is what I thought at the beginning: I just wanted to double check if there was a way to set an object that needs to be synced as a scene object (like in Photon) rather than belonging to the player. I did realize later that this is pointless since that a LockStep connection is made so that only the players' input are taken in consideration. I solved this issue by letting the player to receive the reset input and manage it when necessary so that also the other player will receive the same request.

    As I said, I'll try to make a very simple example together and post it.
    Thanks for the help :smile:
  • Eugenio_IT
    edited July 2017
    Hello @JeffersonHenrique.
    So, I'm going to share a quick demo just to show off the problems I'm having.
    The project can be downloaded from here.

    Please note: despite the name, this is not a working game.
    I'm using Unity 2017.1.0b9.
    The purpose of this project is to test the physics and the player inputs.
    It is possible to make a mobile build and cross test with the editor.
    Also, I did change the TSTrasform script to not hide the position in the editor for debug purposes.

    Under the _Pong/Scenes folder you can find the main scene of the game.

    As you can see, the arena is in the level and when pressing play it will be in the game without issues. After the connection to another player happens, the arena turns into a cross: the Transform position of all the boxes is reset to Vector3.zero.

    To test the physics (aka the ball not bouncing) remove the arena from the scene, open the PongCore.cs script and uncomment the line 130. This will allow the arena to be instantiated directly from the game after TrueSync is connected and fully operational. Running the game now, will show you how the ball doesn't bounce after a collision.

    I'm not adding any comment on how I made all the system to be able to interact together, but, please, feel free to ask if something doesn't look right to you.

    Thank you very much fro your help. :blush:
  • Hello @Eugenio_IT, I will check out your project to see what is going on, but we are a little busy this days with some TS core stuff, the main reason why we open the source code. But as soon as I can I will test your set up, thanks for the send a demo project.
  • Eugenio_IT
    edited July 2017
    No worries @JeffersonHenrique.
    I have no rush for this, also because I managed to make my own bounce algorithm !! :wink:
  • Nice @Eugenio_IT, good luck on that :D.
  • If you remove _serialized = true from

    private void UpdateEditMode() {
    if (transform.hasChanged) {
    _position = transform.position.ToTSVector2();
    _rotation = transform.rotation.eulerAngles.z;
    _scale = transform.localScale.ToTSVector();

    _serialized = true;
    }
    }
    Inside TSTransform2D.cs , then your prefabs will no longer auto inherit the prefab's position. Cheers!
  • Hello @Xelnath and thank you very much for your answer.
    One strange thing is that my prefab was actually correctly positioned. It looks like to me that, somehow, the TSTransform was resetting its position to TSVector.zero and only after the instantiation of TrueSyncManager.
    BTW, I don't really know if it does matter, I was using a TSTransform and not a TSTransform2D. Is the same rule applicable to it?