i have tried to move a player using movement script, it was fine. but if other client collide or force the other client, it makes the gameobject is not sync.
public class PlayerMovement : MonoBehaviour
{
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;
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));
}
// 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);
}
}
im using observe component and observe Photon Transform View but still not sync any movement by force (Only input from client is observed).