- Home /
Two questions with mutliplayer
Okay so I use javascript but I can translate C# to javascript if needed. I have a multiplayer game with tag-specific sounds and animations ect everything is fine except for two things.
Problem #1 is that the players teleport around everywhere and I was wondering if there was any way to Lerp between what player1 sees player2 as and where player2 actually is (if I'm not being confusing)
Problem #2 is that it seems a lot of things don't work for clients, only for hosts. Like my car script, the host can get in, drive around, everything. But the clients can only get into a sitting position and they kinda just float in that sitting position around the map. Also clients cannot perform things like changing variables of scripts, it just doesn't do anything but for the host it's fine.
Now one last thing I should point out is that I AM NOT using Unity 5 or Photon (PUN)
I use plain Unity4 code and everything is fine except for those two.
Okay so I've upgraded to Unity5 and the "Network Transform" component does not work for me and I tried a C# script that seems to work but it sends the client players to the coords (0, [somewhererandom], 0) whenever that player is not moving. When they start moving they start flashing between their position and at 0.
Here's the code: using UnityEngine; using System.Collections; using UnityEngine.Networking;
public class SyncPlayerPos:NetworkBehaviour {
[SyncVar]
private Vector3 syncPos;
[SerializeField] Transform myTransform;
[SerializeField] float lerpRate=15;
void FixedUpdate () {
TransmitPosition();
LerpPosition();
}
void LerpPosition () {
if(!GetComponent<NetworkView>().is$$anonymous$$ine) {
myTransform.position=Vector3.Lerp(myTransform.position, syncPos, Time.deltaTime*lerpRate);
}
}
[Command]
void CmdProvidePositionToServer (Vector3 pos) {
syncPos=pos;
}
[ClientCallback]
void TransmitPosition () {
if(GetComponent<NetworkView>().is$$anonymous$$ine) {
CmdProvidePositionToServer(myTransform.position);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612050251im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I add gravity to my object, and how do I fix my network problem? 1 Answer
More like a bulletin than chat box 0 Answers
Network Chat not sending messages to other clients 1 Answer
Can I connect to a server using the IP adress and the port with the new Unity 5 Networking API?? 0 Answers
unity crashes when script runs 1 Answer