- Home /
Photon / Networking Multiple players, Multiple moving platforms
Driving me mad!
Issue The game has multiple moving platforms that players are "teamed" together on. E.g. Red team on one platform, Blue team on another. Players can spawn on either team, and when the platforms are not moving, the networking works fine. A player can then request to take over control of the platform and can move their own teams platform around.
If two players are on the same platform, when the platform is moved, the 'remote' players stutter around and jump - because the platform is moving, but the Lerping of the remote position is not quite correct. The players are not parented to anything, which could be a solution - but the players should be able to move from their own platform to the other, which makes it even more tricky to accomplish.
Possible Solutions
One solution is to use some sort of clever network extrapolation to smooth out the position of the players, relative to the platform that they are one. I'm not sure if this would work very well though.
Parent each player to their respective platform - this should solve the stuttering of players on the same platform, but then the players on the other platform will have issues. If the player moves from one platform to the other, simply change the parent. Not sure if this can be done seamlessly.
Maybe there is a more obvious solution I am missing?
Give up and become a bin man?
I'm not looking for someone to write a whole system obviously, but any help would be appreciated.
Each player has the following simple network smoothing :
// Update is called once per frame
void Update()
{
if (!photonView.isMine) {
transform.position = Vector3.Lerp (transform.position, this.correctPlayerPos, Time.deltaTime * 8);
transform.rotation = Quaternion.Lerp (transform.rotation, this.correctPlayerRot, Time.deltaTime * 8);
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
// We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
// Network player, receive data
this.correctPlayerPos = (Vector3)stream.ReceiveNext();
this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
Thanks in advance!
Answer by jpthek9 · Jan 27, 2015 at 04:35 PM
You could child the players to a platform and send the local position instead of the global position. Then you use the same smoothing technique except on transform.localPosition. If you want to change platforms, simply detach the child on OnCollisionExit and attach to child to the new platform on OnCollisionEnter.
This is similar to what I tried. I'll try again tonight to see if I can get a working prototype. Will this affect jumping, as jumping would cause OnCollisionExit to be fired.
All localPosition is is the position relative to the parent. If the parent stays still, absolutely nothing happens. If the parent moves right, the unit will move right as much as the parent did. If you jump, make sure you detach the child by calling
transform.parent = null;
so you don't move with the platform while in the air. Then when you finish jumping, simply attach the object again. i.e.
void OnCollisionExit (Collision col) //jumping or falling off
{
if (col.transform == transform.parent)
transform.parent = null;
}
void OnCollisionEnter (Collision col) //landing on the platform
{
if (col.transform.tag == "Platform")
transform.parent = col.transform
}
Your answer
Follow this Question
Related Questions
Photon Network syncing the transform of a moving platform 0 Answers
[Photon]Player vs. Player Collision 0 Answers
Correct way to design turn based multiplayer using Photon Unity Networking. 0 Answers
how do i apply damage to objects other that the player 1 Answer
Photon Unity Network - Refresh/Tickrate 2 Answers