Player position not sync on for different playe

Options
My level contains a platform and the players have the ability to jump and to move around. Everything works fine until a player jumps under the platform and starts jumping against the ceiling. On the screen of the player it looks just fine but on the screen of the others it looks like he is falling. I am very new to photon and have no idea how to fix this.
This is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerMovement : Photon.MonoBehaviour
{
    public PhotonView photonView;
    public Rigidbody2D rb;

    private Vector3 selfPos;

    public float moveSpeed;
    public float jumpForce;
    public bool devTesting = false;

    private void FixedUpdate()
    {
        if (!devTesting)
        {
            if (photonView.isMine)
                checkInput();
            else
                smoothNetMovement();
        }
        else
        {
            checkInput();
        }
    }

    private void checkInput()
    {
        if(Input.GetAxisRaw("Horizontal") > .5f || Input.GetAxisRaw("Horizontal") < -.5f)
        {
            rb.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * moveSpeed, rb.velocity.y);
        }
        else if (Input.GetAxisRaw("Horizontal") < .5f || Input.GetAxisRaw("Horizontal") > -.5f)
        {
            rb.velocity = new Vector2(0f, rb.velocity.y);
        }
        if(Input.GetAxisRaw("Jump") > .5f)
        {
            rb.velocity = new Vector2(rb.velocity.x, Input.GetAxisRaw("Jump") * jumpForce);
        }
    }

    private void smoothNetMovement()
    {
        transform.position = Vector3.Lerp(transform.position, selfPos, Time.deltaTime * 8);
    }

    private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            stream.SendNext(transform.position);
        }
        else
        {
            selfPos = (Vector3)stream.ReceiveNext();
        }
    }
}

Answers

  • PB_Xander
    Options
    You're using Rigidbody and force application for movement, but on the client side you trying to directly affect the position of the object, and that is totally not right. First of all, learn more about Unity's basic principles and object's behaviors (Unity Learn, Forums etc), then put your hands on any sort of networking.