How to instantiate the player and Sync Animation and Transfrom in muliplayer.
by user 406778568597831690
How to instantiate the player and Sync Animation and Transfrom in muliplayer.
by user 406778568597831690
Good start would be the docs
There’s a sample being created to explain this usecase more easily.
In the mean time, the docs are a good start to exaplin the basics of networking.
And then there are the Player State and SyncTransform. You can see the usage here: https://github.com/needle-tools/needle-engine-samples/blob/sample/networking/package/Runtime/Networking/Player/Scripts/NetworkingPlayer~/Player.ts
To make the SyncTransform work, you need to call the requestOwnership()
on it, but only on a instance that is yours (the local instance).
That’s where IsOwner boolean comes in, that is calculated from PlayerState
like this:
isOwner(): boolean {
if(!this.playerState || !this.playerState.owner)
return false;
return this.playerState.owner == this.context.connection.connectionId;
}
You can condition the inputs as well, so the synced players are not moving with your controls and only your local instance is being moved.
Lastly, there is the PlayerSync, where you specify what the player prefab is. Ten when ever a player connects it spawns this prefab.
So at the end it’s quite simple
You can copy this folder and try it out yourself.
https://github.com/needle-tools/needle-engine-samples/tree/sample/networking/package/Runtime/Networking
.
.
Don’t be afraid to ask if anything isn’t clear. Like, what is a prefab or if some of my wording isn’t clear
I had tried these components earlier, without the ownership it didn’t work is it like if we add these components without the ownwership it will not instanciate ??
by user 406778568597831690
requestOwnership()
but only on a instance that is YOU / the local player, not the remotes ones. (That’s why you need to condition the call with isOwner
func- in the Player.ts)So to answer your question:
No, syncTransform doesn’t instantiate anything. Regardless of the requestOwnership()
call.
The PlayerSync is the one that spawns/instantiates the player.
so the Player orefab inspector is like this,
by user 406778568597831690
and player component is like this,
by user 406778568597831690
i have modified the player script, made sure whatever code is there gets translated
by user 406778568597831690
Ok, that seems to be correct What issues do you currently have?
player is not moving
by user 406778568597831690
Can you post the playermovement script
this is my script
by user 406778568597831690
I see, if you commend out the is Owner check and the return above it, does it work then?
no stil not working i added a log to check whether its getting instantiated, its getting instantiated but movement is not working
by user 406778568597831690