Sorry that I bump the thread up again, but 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). If you dont followed the thread: 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.
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);
}
}
}
Code on the Platform:
using UnityEngine;
using System.Collections;
public class PlatformNetworkController : Photon.MonoBehaviour {
public bool ja = false;
public bool links = false; // move up, down, right etc.
public bool rechts = false;
public bool oben = false;
public bool unten = false;
public int geschwindigkeit = 0;
// MouseLook camScript;
// CharacterMotor controllerScript;
// FPSInputController controllerScript2;
// Use this for initialization
void Awake () {
}
void Start() {
}
// Syncronisation von Position, Rotation usw.
[RPC]
void SendMessage(int geschw, Vector3 pos, Quaternion rot)
{
transform.position = pos;
transform.rotation = rot;
geschwindigkeit = geschw;
ja = !ja;
}
[RPC]
void Links()
{
links = !links;
}
[RPC]
void Rechts()
{
rechts = !rechts;
}
[RPC]
void Oben()
{
oben = !oben;
}
[RPC]
void Unten()
{
unten = !unten;
}
void FixedUpdate()
{
if ((Input.GetButtonDown("E") )) {
photonView.RPC("SendMessage", PhotonTargets.All, 5, transform.position, transform.rotation);
}
if (ja == true) {
transform.Translate(0 , 0 , geschwindigkeit * Time.deltaTime) ; // Z direction
}
if (Input.GetButtonDown("G")) {
photonView.RPC("Rechts", PhotonTargets.All);
}
if (Input.GetButtonUp("G")) {
photonView.RPC("Rechts", PhotonTargets.All);
}
if (rechts){
transform.Rotate(0 ,-30 * Time.deltaTime , 0);
}
if (Input.GetButtonDown("J")) {
photonView.RPC("Links", PhotonTargets.All);
}
if (Input.GetButtonUp("J")) {
photonView.RPC("Links", PhotonTargets.All);
}
if (links){
transform.Rotate(0, 30 * Time.deltaTime, 0);
}
if (Input.GetButtonDown("Z")) {
photonView.RPC("Oben", PhotonTargets.All);
}
if (Input.GetButtonUp("Z")) {
photonView.RPC("Oben", PhotonTargets.All);
}
if (oben){
transform.Translate(0 ,4 * Time.deltaTime , 0);
}
if (Input.GetButtonDown("H")) {
photonView.RPC("Unten", PhotonTargets.All);
}
if (Input.GetButtonUp("H")) {
photonView.RPC("Unten", PhotonTargets.All);
}
if (unten){
transform.Translate(0, -4 * Time.deltaTime, 0); // Z direction
}
}
}
Fps control script:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(CharacterController))]
public class Firstpersoncontrol : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private bool isLocalPlayer = false;
public void SetIsLocalPlayer(bool val) {
isLocalPlayer = val;
}
private Vector3 moveDirection = Vector3.zero;
void Update() {
if (!isLocalPlayer) return;
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
There are some german words in the code, but I hope it is clear. In the ship network code the button you push determines in which direction the platform moves. I hope someone can help me by reading the network code I posted :).