Confusion on how position syncing works (Example in description)
Options
Lagidigu
✭
Hi there!
I am currently developing a game in which each client instantiates one Player Gameobject, and each Player has this script attached to it. Every time a player dies, I want to disable smoothing, because said player gets teleported to a certain part of the map.
I call "triggerShouldntSmoothOnOff" in a separate script, and the movement only happens locally if the player isMine.
As you can see, the idea is that we should temporarily switch to a syncing that is without lerp, and then back. This doesn't work though, where the Player still has smoothing turned on... I know that it isn't due to the time between switchting the bool on and off, as I have tried multiple seconds, and it still doesnt work.
Sitting on this problem now for 3 days straight, and I cannot wrap my head around what is causing the problem. If you want to get the code of where "triggerShouldntSmoothOnOff" is getting called, just tell me, but I doubt that it is causing the problem.
using UnityEngine;
using System.Collections;
public class ObjNetworkSyncWithSmoothing : Photon.MonoBehaviour {
Vector3 position;
Quaternion rotation;
public float smoothingSpeed = .2f;
public bool shouldntSmooth;
void Start ()
{
if (!photonView.isMine)
{
StartCoroutine("UpdateData", 1f);
}
}
public void triggerShouldntSmoothOnOff()
{
StartCoroutine(shouldntSmoothOnOff());
}
IEnumerator shouldntSmoothOnOff()
{
shouldntSmooth = true;
yield return new WaitForFixedUpdate();
yield return new WaitForFixedUpdate();
shouldntSmooth = false;
}
IEnumerator UpdateData(float time)
{
yield return new WaitForSeconds(time);
while (true)
{
if (!shouldntSmooth)
{
transform.position = Vector3.Lerp(transform.position, position, smoothingSpeed);
transform.rotation = Quaternion.Lerp(transform.rotation, rotation, smoothingSpeed);
}
else
{
transform.position = position;
transform.rotation = rotation;
}
yield return new WaitForFixedUpdate();
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if(stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
position = (Vector3)stream.ReceiveNext();
rotation = (Quaternion)stream.ReceiveNext();
}
}
}
I would be erternally grateful if you could help me out with that!
Thanks a lot in advance!
Cheers,
Luke
I am currently developing a game in which each client instantiates one Player Gameobject, and each Player has this script attached to it. Every time a player dies, I want to disable smoothing, because said player gets teleported to a certain part of the map.
I call "triggerShouldntSmoothOnOff" in a separate script, and the movement only happens locally if the player isMine.
As you can see, the idea is that we should temporarily switch to a syncing that is without lerp, and then back. This doesn't work though, where the Player still has smoothing turned on... I know that it isn't due to the time between switchting the bool on and off, as I have tried multiple seconds, and it still doesnt work.
Sitting on this problem now for 3 days straight, and I cannot wrap my head around what is causing the problem. If you want to get the code of where "triggerShouldntSmoothOnOff" is getting called, just tell me, but I doubt that it is causing the problem.
using UnityEngine;
using System.Collections;
public class ObjNetworkSyncWithSmoothing : Photon.MonoBehaviour {
Vector3 position;
Quaternion rotation;
public float smoothingSpeed = .2f;
public bool shouldntSmooth;
void Start ()
{
if (!photonView.isMine)
{
StartCoroutine("UpdateData", 1f);
}
}
public void triggerShouldntSmoothOnOff()
{
StartCoroutine(shouldntSmoothOnOff());
}
IEnumerator shouldntSmoothOnOff()
{
shouldntSmooth = true;
yield return new WaitForFixedUpdate();
yield return new WaitForFixedUpdate();
shouldntSmooth = false;
}
IEnumerator UpdateData(float time)
{
yield return new WaitForSeconds(time);
while (true)
{
if (!shouldntSmooth)
{
transform.position = Vector3.Lerp(transform.position, position, smoothingSpeed);
transform.rotation = Quaternion.Lerp(transform.rotation, rotation, smoothingSpeed);
}
else
{
transform.position = position;
transform.rotation = rotation;
}
yield return new WaitForFixedUpdate();
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if(stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
position = (Vector3)stream.ReceiveNext();
rotation = (Quaternion)stream.ReceiveNext();
}
}
}
I would be erternally grateful if you could help me out with that!
Thanks a lot in advance!
Cheers,
Luke
0
Comments
-
No one that can help me?
This seems to be a pretty common issue, as it is related so syncing...0