Help us understand the problem. What is going on with this article?

Photonを使ってのカメラワーク

FPSなどのゲームをつくって自分からのカメラ視点を設定した場合

Photonなどのネットワークを介して動作したときにカメラの視点がうまく
自分の視点に切り替わらなかったのでその時の対処法を備忘録的に、、

photonManager的スクリプトで
// マッチングが成功した時に呼ばれるコールバック
public override void OnJoinedRoom()
{
// マッチング後、ランダムな位置に自分自身のネットワークオブジェクトを生成する
GameObject camera PhotonNetwork.Instantiate("Camera",player.transform.position,Quaternion.identity);
}
いたって簡単で
cameraのスクリプトに
if(!photonView.IsMine)
{
gameObject.SetActive(false);
}
にするだけでした。

ちなみに私のプレーヤー追従のカメラスクリプトは以下です
参考までに

void FixedUpdate()
{
if(!photonView.IsMine)
{
gameObject.SetActive(false);
}

    if(photonView.IsMine)
    {
        // カメラの位置を設定
        Transform player = GameObject.FindGameObjectWithTag("Player").transform;


        var desiredPos = player.position - player.forward * baseDistance + Vector3.up * baseCameraHeight;

        cam.position = Vector3.Lerp(cam.position, desiredPos, Time.deltaTime * chaseDamper);

        // カメラの向きを設定
        cam.LookAt(player);
    }





}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした