- Home /
Networking syncing player on moving object
hey i realy need some help
im making a multiplayer boat game and i need to sync the players the boats have been synced and they plays need to stand on them when they move around
the major problem im having is i cant get the player to smoothly stay on the ship
im using the c# version on the character motor for keeping him moving with the platform but when i try to sync the players they start juttering backwards and forwards the faster i go.
code: void FixedUpdate () { if(photonView.isMine == false && PhotonNetwork.room != null) { Player_Move_Network(); } }
void Player_Move_Network()
{
if(!DoneFirstUpdate && GotFirstUpdate)
{
transform.position = NetworkPosition;
transform.rotation = NetworkRotation;
DoneFirstUpdate = true;
}else{
//float pingInSeconds = (float)PhotonNetwork.GetPing() * 0.001f;
//float timeSinceLastUpdate = (float)(PhotonNetwork.time - LastNetworkDataReceivedTime);
//float totalTimePassed = pingInSeconds + timeSinceLastUpdate;
//Vector speed = new Vector3(transform.position - lastpos).magnitude;
//Vector3 exterPolatedTargetPosition = NetworkPosition + transform.forward * speed * totalTimePassed;
//Vector3 NewPosition = Vector3.MoveTowards(transform.position, exterPolatedTargetPosition, speed * Time.deltaTime);
//***POSITION***\\working
////if(Vector3.Distance(transform.position, exterPolatedTargetPosition) > 2f)
//{
// NewPosition = exterPolatedTargetPosition;
//}
//transform.position = NewPosition;
Vector3 VelocityToAddFromPosition = NetworkPosition - lastpos;//this is calculating how much velocity you need to add so they ships resync there position
Vector3 NewPosition = transform.position + VelocityToAddFromPosition;// this calculates the last known velocity and adds the velocity so ships can re align THE 2 is so it doesnt lag behind
//rigidbody.velocity = Vector3.Lerp(rigidbody.velocity, NewVelocity, 2f * Time.deltaTime);//this lerps the velocity
transform.position = Vector3.MoveTowards(transform.position, NetworkPosition, 10f * Time.deltaTime);
//Vector3.Lerp(transform.position, NewPosition, 10f * Time.deltaTime);
//transform.position = Vector3.MoveTowards(
lastpos = transform.position;//sets the last position
//***ROTATION***\\Not working TRY AGAIN EDITED IT
transform.rotation = Quaternion.RotateTowards(transform.rotation, NetworkRotation, 1f * Time.deltaTime);
as you can see ive tryed alot of different thing to try to get it to work (they are my commented out bits)
my idea is instead of chaning the position with transform.position = can i use transform.position += so it might not jutter as much
thanks for reading and please help ive been trying to fix this for a long time