- Home /
Multiplayer - Other players shaking back and fourth on moving platform
I really don't know what else i could try to make this work. This is the network code i got currently in the project. It's very basic and just vor testing purposes(i use the photon network engine). My problem is that if two or more players stand on a moving platform, the other players you are looking at with your own player shake back and fourth violently and appear a little bit behind the position they are on their own screen. This only happens on a moving object, on a firm ground everything works fine. Your own player doesnt shake, so i think its a problem with the network code. I tried many different things but I dont get it to work and really got no idea what the problem could be. I also used other methods like the Character Motor + FpsInput controller for the movement of the players, but that doesnt changed anything. I also tried to stream the movement of the ship the same way like the players and not with rpcs and I also parented the players to the ship(like you can see in the code below). I further tried to move the ship with add.relative force instead of transform.Translate. But none of this solved the problem. In the current version no rigidbody is attached to the platform or the players.
Network Code on the players:
using UnityEngine;
using System.Collections;
public class NetworkController : Photon.MonoBehaviour {
MouseLook camScript;
Firstpersoncontrol controllerScript;
// Use this for initialization
void Awake () {
camScript = GetComponent<MouseLook>();
controllerScript = GetComponent<Firstpersoncontrol>();
GameObject Platform = GameObject.Find("PlatformPrefab");
transform.parent = Platform.transform;
}
void Start() {
//Either own player or a remote Instantisted player
if (photonView.isMine)
{
camScript.enabled = true;
Transform camTrans = Camera.main.transform;
camTrans.parent = transform;
camTrans.localPosition = new Vector3(0, 1, 0);
camTrans.localEulerAngles = new Vector3(10, 0, 0);
}
else{
camScript.enabled = false;
}
controllerScript.SetIsLocalPlayer(photonView.isMine);
}
// Syncronisation von Position, Rotation usw.
private Vector3 correctPosition = Vector3.zero;
private Quaternion correctRotation = Quaternion.identity;
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
correctPosition = (Vector3)stream.ReceiveNext();
correctRotation = (Quaternion)stream.ReceiveNext();
}
}
void FixedUpdate()
{
if(!photonView.isMine)
{
transform.position = Vector3.Lerp(transform.position, correctPosition, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, correctRotation, Time.deltaTime * 5);
}
}
}
I hope someone can help me :).
I'm having a similar problem. Did you ever solve it? Or still looking for an answer?
Answer by aldonaletto · Sep 07, 2012 at 01:47 AM
It seems that the problem is caused by the time the network info takes to reach the client: the position/rotation info received from the network is always somewhat outdated, since the players are moving with the platform. A possible solution could be to use localPosition and localRotation instead of position and rotation
But case the players can leave the platform, be sure to update their parent properties before applying the position/rotation network info: localPosition and localRotation return position and rotation when the object isn't childed to anything, thus the player will be kicked to far far away until its property parent gets synchronized.
With my scenario I have a character controller using the character motor having trouble with smooth movement when standing on a platform which is being moved by another player via RPC. I can't just attach a network view to the platform because the player who controls the platform can change within the game. Do you have any suggestions?
Thanks.
Hi Aldo Naletto, this was indeed the solution for the problem :). However, I dropped the parenting thing now, because I often read that it could cause problems later and I realize why this might be the case. The player move along with the platform with some code, now and this works fine. Sadly, I can not sync localPosition and Rotation anymore because the players arent parented to the platform anymore. Any idea how i can achieve a similiar result, but without parent the players to the platform?
I'm using a RPC that the server sends the position and rotation of the platform for all the players. However, The platform is in a completely different place for the client if sending out the localRotation and localPosition, so its out of sync. How did you get yours to work? Also I am using a character motor, so I'm not parenting anything to the platform. I would recommand to use the character motor for yours as well.
Answer by supamigit · Jun 08, 2014 at 03:12 PM
well after doing a few section of Quils FPS tutorial using Photon... its come to my conclusion ANYTHING that moves on both yours and the networked player screen needs to be disabled and called AFTER the game starts
As you see in the code im using
GameObject = myPlayerGO
//C# format for Networked Players they are all disabled - and replaced <> with " " due to forum
myPlayerGO.GetComponent"MouseLookOut"().enabled = true;
myPlayerGO.GetComponentInChildren"Camera"().enabled = true;
myPlayerGO.GetComponentInChildren"MouseLookFPS"().enabled = true;
myPlayerGO.GetComponentInChildren"AudioListener"().enabled = true;
im enabling the component After the Photon initialises everything it needs, and this is only on things that move and are not STATIC...
so with that knowledge i would add the Movable platform the same way to make sure the server give true relation to
what you see
vs
what the server see
vs
what the networked player sees..
this seemed to work testing a movable platform with what i have right now and it translated perfect... well as good a simple networking script can go...
My scripts up to vid 7 is on my google drive - check it out if you like Google Drive