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.
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.