- Home /
Question by
GGWP-senpai · Apr 05, 2020 at 05:38 PM ·
photonnetworkplayer
OnPhotonSerializeView sync is so lag
event in the same network, i try in Pc and my mobile. is it something wrong with my code? i follow the instruction using OnPhotonSerializeView and using stream. and also trying in new project works fine. i dont know what is wrong with my code..
private PhotonView pv;
private CharacterController myCC;
public float walkSpeed = 2;
public float runSpeed = 4;
public float rotationSpeed;
float speed;
public FixedJoystick leftjoystick;
public FixedButton button;
//Player Component for Stream
private Rigidbody rb;
private Transform tf;
Quaternion targetRotation;
// Start is called before the first frame update
void Start()
{
pv = GetComponent<PhotonView>();
myCC = GetComponent<CharacterController>();
leftjoystick = (FixedJoystick)FindObjectOfType(typeof(FixedJoystick));
button = (FixedButton)FindObjectOfType(typeof(FixedButton));
rb = transform.Find("Player").GetComponent<Rigidbody>();
tf = transform.Find("Player").GetComponent<Transform>();
Debug.Log(tf.name);
Debug.Log(rb.name);
}
// Update is called once per frame
void Update()
{
if (pv.IsMine)
{
if (button.Pressed)
{
speed = runSpeed;
}
else
{
speed = walkSpeed;
}
BasicMovement();
BasicRotation();
}
}
void BasicMovement()
{
Vector3 targetDirection = new Vector3(leftjoystick.input.x,0, leftjoystick.input.y);
myCC.Move(targetDirection * Time.deltaTime*speed);
if (Input.GetKey(KeyCode.W))
{
myCC.Move(transform.forward * Time.deltaTime * speed);
}
if (Input.GetKey(KeyCode.A))
{
myCC.Move(-transform.right * Time.deltaTime * speed);
}
if (Input.GetKey(KeyCode.S))
{
myCC.Move(-transform.forward * Time.deltaTime * speed);
}
if (Input.GetKey(KeyCode.D))
{
myCC.Move(transform.right * Time.deltaTime * speed);
}
}
void BasicRotation()
{
//targetRotation = Quaternion.Euler(0, angle, 0);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
// stream.SendNext();
// stream.SendNext();
// stream.SendNext();
stream.SendNext(rb.velocity);
stream.SendNext(rb.rotation);
stream.SendNext(rb.position);
stream.SendNext(tf.position);
stream.SendNext(tf.rotation);
}
else
{
rb.velocity = (Vector3)stream.ReceiveNext();
rb.rotation = (Quaternion)stream.ReceiveNext();
rb.position = (Vector3)stream.ReceiveNext();
tf.position = (Vector3)stream.ReceiveNext();
tf.rotation = (Quaternion)stream.ReceiveNext();
}
}
Comment
Your answer
Follow this Question
Related Questions
Can't see other player over the network 0 Answers
PhotonNetwork Position, rotation is not sync after force of other client. 1 Answer
Stange Error, please help... 0 Answers
Photon PUN and persistence 0 Answers