multiple players control over one game object

Hey,
I’m currenty developing a game where many players interact together on one flying ship. Everyone should be able to fly(navigate) the ship(if no other currently is on the rudder). But only the owner of the ship can navigate it so the other players see it move, but i want that every player can control it. Also the other players(non owners) jiggle around on the ship when it flys or fall of the ship, the owner does not, even when he walks around while it flys. When a player who is not the owner of the ship trys to control it, it doesn’t move on his screen and also the other players don’t see the ship moving.
Somebody got an idea how to solve this problem so the other players behave the same like the owner of the ship?
I’m developing the game with the photon network plugin, but maybe it is the same with the unity network system.
Sorry for my englisch, I hope you understood the question :slight_smile: .

Update:

Can’t you use a bool for it?
like:

bool canControl = false;

void Update () {
if(canControl){
[control commands here]
}
}

And only the player who has canControl == true will have effect on the ship.

Hey,
Thanks for you answer but that is not the problem.
It seems so that only the network owner of the objekt (ship), in my case the first player who enters the room(then the ship gets spawned and the player is the network owner of the ship), can control the ship and send network data(like position and rotation) to the other players in the room. The other players aren’t able to do this, only the owner(But i want that every player can do this, not just the owner). And only the owner can run around on the ship when it is moving without getting problems(like jiggle of the screen or falling off the ship). So propably it is a network code issue.
I hope everything is clear, now :).

you can spawn 1 ship, and make it server controlled. the other players can go to the rudder and enable shipControl script, and while this script is activated, they send the commands to the server (via RPC in unity’s networking), which move the ship. this way all the players can control your moving ship (tho the moving is done only on the server, and synchronized on the other players clients).

I hope you understand what I am trying to say here.

Hey ar0nax,
thanks for your answer :).
That is probably the best solution, I’ll try this :).

this method of having a server driven object is only possible when you are controlling your own Photon Servers I am thinking that way… everything i have read shows that you can’t use server side logic on their 100% Hosted model… hmmm trying to get a game in dev and need to know which way to go…

A player system might be the server I this case, he wasn’t very clear about the actual network implementation.

Hi,

I solved the problem that only one player can control the ship by using RPCs, smiliar to what ar0nax mentioned. But still, when the ship is moving and you look to the other players they shake back and fourth violently. Also they seems to be a little bit behind the position they are on their own screen. This only happens when the ship is moving. When the players aren’t on a moving object, everything seems fine. I struggle with this problem a long time, now :/. Somebody got an idea how to solve it?

Did someone created a multiplayer game with unity where players are on a moving object and can help me with my problem? I tried many things but nothing solved the shaking of the other players.

try parenting the players to that moving object, and make them move only inside that object (localposition and stuff), that should fix the shaking i think.

Thanks for your answer :).
Only the other players you are looking at shakes back and fourth when the object is moving, not your own player. So i can’t imagine it is a problem with the game code itself, but the network code. Why do you think this will fix it? I’m currently using the first person controller for player movement, if this helps.

well if you are using the first player controller uses physics to move your character, and via Network, when dealing with rigidbodies it’s a bit more complicated, try reading here: http://forum.unity3d.com/threads/119907-Dead-Reckoning-for-racing-games-What-are-some-good-ideas

trouble with interpolation, extrapolation, and smoothing out movement in between.

The character controller uses physics? I always thought it does not. “The Character Controller is mainly used for third-person or first-person player control that does not make use of Rigidbody physics.” I also did not apply a rigidbody to my player. I’m aware of physics problems in network so i hoped the character controller does not use -real- physics. Or did i misunderstood something?

The character controller doesn’t, which is why they usually get wonky when you put them on top of moving objects (ie: an object with physics being applied to it). Usually the solution is parenting.

I tried using simple move instead of character Controller and Fps input controller and parented the players to the object, now. But still the other players you are looking at shake back and fourth when the object starts moving, but not your own player. It seems a bit less then before, but that doesnt solve it. I don’t move the ship with physics, but with transform.translate, but I also tried using physics. That doesnt change anything.

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 :).