- Home /
Question by
InYourEyes · Apr 04, 2021 at 03:36 PM ·
photonvisual studioonline game
Photon Character controls are swapping
Hi I'm trying to make an online game in Unity using PhotonNetwork but I got a problem. Whenever the second player joins the game the first clients camera is switches to the second clients camera the second clients camera switches to the first clients camera. I'm using "photonView.IsMine" to control the clients. This is my script :
private CharacterController controller = null; {
public float speed = 6f;
public float turnSmoothTime = 0.1f;
float turnSmoothVelocity;
public Transform cam;
public Animator anim;
Vector3 moveVector;
private void Start()
{
controller = GetComponent<CharacterController>();
}
private void Awake()
{
if (!photonView.IsMine && GetComponent<PlayerMovement>() != null)
{
Destroy(GetComponent<PlayerMovement>());
}
}
private void Update()
{
if (!photonView.IsMine)
{
TakeInput();
}
private void TakeInput()
{
moveVector = Vector3.zero;
anim.SetFloat("vertical", Input.GetAxis("Vertical"));
anim.SetFloat("horizontal", Input.GetAxis("Horizontal"));
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if (direction.magnitude >= 0.1f)
{
float targetAngel = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngel, ref turnSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDirection = Quaternion.Euler(0f, targetAngel, 0f) * Vector3.forward;
controller.Move(moveDirection.normalized * speed * Time.deltaTime);
}
if (controller.isGrounded == false)
{
moveVector += Physics.gravity;
}
controller.Move(moveVector * Time.deltaTime);
}
}
Comment
Answer by iamdevil19970 · Mar 05 at 07:29 AM
same with me!!!!!! they just swap the controls but i think i can make cool puzzeles with it!!!!
but will definatly try to fix it!!