Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@ryo10410

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

More than 1 year has passed since last update.

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);
    }





}
0
Help us understand the problem. What is going on with this article?
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.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?