- Home /
Question by
ScrappyCocco · Mar 28, 2014 at 06:47 PM ·
networkingprefabmultiplayerplayer
I have problem with synchronize multiplayer player position...
Hi to all... I'm trying to do a simple Multiplayer game... I have a player prefab like this:
but with script:
if (stream.isWriting)
{
syncPosition = rigidbody.position;
stream.Serialize(ref syncPosition);
syncPosition = rigidbody.velocity;
stream.Serialize(ref syncVelocity);
}
else
{
stream.Serialize(ref syncPosition);
stream.Serialize(ref syncVelocity);
syncTime = 0f;
syncDelay = Time.time - lastSynchronizationTime;
lastSynchronizationTime = Time.time;
syncEndPosition = syncPosition + syncVelocity * syncDelay;
syncStartPosition = rigidbody.position;
}
}
or with script:
if (stream.isWriting)
{
Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
}
else
{
Vector3 pos = Vector3.zero;
Vector3 velocity = Vector3.zero;
Quaternion rot = Quaternion.identity;
Vector3 angularVelocity = Vector3.zero;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
}
}
the player spawn but the position isn't synchronized... Yes i have a component rigidbody in the prefab "Personaggio" and all scripts are here like this:
then what i have to do? Please help i'm in panic!
Ps: the ifs are into the void:`void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)` and i have forgot that before the ifs there are the code:
Vector3 syncPosition = Vector3.zero;
Vector3 syncVelocity = Vector3.zero;
Please help!
cattura.png
(5.7 kB)
cattura2.png
(19.4 kB)
Comment
Your answer
Follow this Question
Related Questions
Unity Multiplayer - Instantiate prefab 1 Answer
Unity networking tutorial? 6 Answers
Multiplayer Implimentation on 2D Character 0 Answers
'NetworkTranformChild' problem 1 Answer
Multiplayer prefab player fall through floor on instantiate 0 Answers