a) A Networking empty object with SyncedRoom: Networking(Script)
b) A player prefab, this prefab has a model, its own character controller script (as a child), a camera (and this camera has the component SyncedCamera) and the component PlayerState.
c) Two empty objects both with the component PlayerSinc and the Asset Field of this component has the prefab described in b).
What’s happening?
When I open two browser windows and try to move one of the characters, I move both. How can I have a independent control in both windows?
Attach my Networking object :
Thank you all, you have been people who help me understand this great new engine.
You have your local player that you wish to control, but you also have the remote player, with the same scripts. These scripts ask for input and thus move the instance around.
The is owner function is the important bit. ||(This code works, but is bit outdated, the PlayerState has a isLocalPlayer() function that has the same implementation, just so you know)||
—
Also you don’t meantion SyncedTransform, see the implementation above on how to use it. The position of the player is not synchronized without calling the requestOwnership(); on the local player.
—
Let me know if you would get stuck with anything or if something isn’t clear
Simplest is to clone the repo: git clone https://github.com/needle-tools/needle-engine-samples
checkout the netwokring branch: git checkout samples/networking
And then add the samples package to your unity (that will also replace the one downlaoded before, if you did that)
By opening the package manager, clicking the + → add from disk and locate the package.json that is in the downloaded samples at package/package.json
I have a question. I have been checking the Networking example, with the SynCamera object which has the Synced Camera script with its Camera Prefab = CameraPrefab (a object that has not a camera, it has the body and eye model). Is this object which"Instantiate" a new player with its own camera when another browser window is open ?
Ah, had to get familiar with the SyncedCamera since i haven’t used it before.
It implements all networking into itself and it is a self sufficient system. It doesn’t use PlayerSync or PlayerState.
That’s why the PlayerState.isLocalPlayer will always return false, because the script needs to be told who is the owner. That is what PlayerSync does.
So i would advice to use PlayerSync to spawn your player upon joining and then your controller should reference your PlayerState on your instanced player and condition the input with isLocalPlayer. And do not use SyncedCamera for this usecase.
Also, then your position and rotation won’t be updated, so you need to add the SyncedTransform as well and request the ownership.
Okey. I’m doing a third person controller game. The player can move around a terrain with planes and 3D primitives objects . He moves and jumps.
Player(Funtional Cube) has :
Rigibody
BoxCollider
ThirdPersonController homemade script
The importat children are the LookAt which holds the Camera in order to generate the third person perspective. And the second is the PJ, now is just a Cube but It can be replace to be any 3D model.
But I think that this is the importat part tha you mentioned “So i would advice to use PlayerSync to spawn your player upon joining and then your controller should reference your PlayerState on your instanced player and condition the input with isLocalPlayer”
Alterantive way to still have some logic running is to add if statements through out your code to define what runs on remote players and what on local ones