code VR

Unity×VR(186)

スポンサーリンク

//tips

//微調整

プレイヤー消滅を確認して生成されるGhostcameraの移動スクリプトを修正する。

現在は自身が向いている方向から左右前後へ移動できていないのでそちらの動きを可能にさせる。これは現在のプレイヤーの動きと同じ。

Photon同期・アニメーション設定も必要ないので下記の形でシンプルにした。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GhostMove : MonoBehaviour
{
Rigidbody rb;

bool Inverseflag = true;

public float rabbitspeedup = 10;

float wolfspeed = 1;

void Start()
{
rb = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
// Upキーで前に進む
if (Input.GetKey("up"))
{
Inverseflag = true;

Vector3 moveForward = transform.position + transform.forward * 100;
moveForward.y = 0;
rb.position = transform.position + transform.forward * 1.5f * Time.deltaTime * rabbitspeedup * wolfspeed;

}

// Downキーで後ろに進む
if (Input.GetKey("down"))
{

if (Inverseflag)
{
Vector3 moveForward = transform.position - transform.forward * 500;
moveForward.y = 0;

Quaternion targetRotation = Quaternion.LookRotation(moveForward);

transform.rotation = targetRotation;
Inverseflag = false;
}

rb.position = transform.position + transform.forward * 1.0f * Time.deltaTime * rabbitspeedup * wolfspeed;

}

//right キーで右に進む
if (Input.GetKey("right"))
{
Inverseflag = true;

Vector3 moveForward = transform.position + transform.right * 500;
moveForward.y = 0;

Quaternion targetRotation = Quaternion.LookRotation(moveForward);

transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 2 * Time.deltaTime);

rb.position = transform.position + transform.forward * 2.0f * Time.deltaTime * rabbitspeedup * wolfspeed;

}

//left キーで左に進む
if (Input.GetKey("left"))
{
Inverseflag = true;

Vector3 moveForward = transform.position - transform.right * 500;
moveForward.y = 0;

Quaternion targetRotation = Quaternion.LookRotation(moveForward);

transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 2 * Time.deltaTime);

rb.position = transform.position + transform.forward * 2.0f * Time.deltaTime * rabbitspeedup * wolfspeed;

}
}

}

正常に機能した。

if (mycamera!=null)を付加し、プレイヤーが消滅した場合の対処として、HPUICameraLookatスクリプトの調整も行った。

また、時々、プレイヤーの方を向かないHPUIが存在するので要因を調べる。

全てのプレイヤーに組み込まれているカメラには生成主のみアクティブにするスクリプトが記載されているので基本的にシーンにはMainCameraは一つしか存在していないはず。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class Mycamornot : MonoBehaviourPunCallbacks
{
void Start()
{
if (photonView.IsMine)
{
this.gameObject.SetActive(true);
}
else
{
this.gameObject.SetActive(false);
}
}
}

自身のmycameraがオフになる前にHPUIの方でmycameraを取得してしまっているの可能性があるのでmycamera = GameObject.FindWithTag("MainCamera").GetComponent<Camera>();の処理を少し遅らせる方法を考える。

Camera側からfindの発生時点を指定して行わせるようにした。

if (photonView.IsMine)
{
this.gameObject.SetActive(true);
HPUICameraLookat.MyCamStart();
}

変更を加えたが生成プレイヤーの方にHPUIが向かないのでデバッグでどのカメラを取得しているかを確認する。

photonView.IsMineで判別しようとしているにもかかわらずphoton viewコンポーネントがカメラにアタッチされていなかった。

アタッチしたがそれでもログが出てこない。スクリプトを見直すとカメラコンポーネントを取得していたので、その必要ないのでオブジェクトとして取得した。

GameObject mycamera;

public void MyCamStart()
{
mycamera = GameObject.FindWithTag("MainCamera");

それでもUIが常にプレイヤーの方に向いて表示されない。こちら検証していく。

 

人気の記事

1

皆さん、ついに、エアラインでも、サブスクリプションが始まったのはご存じですか? まだ実験段階ですが、ANAが、定額全国住み放題サービスを提供する「ADDress」と組んで、国内線を4回まで定額利用可能 ...

2

無料でネットショップを開けるアプリとして多くの人に驚きを与えたBASE株式会社が、2019年10月25日東証マザーズに上場しました。2020年2月時点で90万店を超えるショップを抱えるまでに成長してい ...

3

2011年にサービスを開始してから圧倒的な成長率を誇るインテリア通販サイト 【FLYMEe/フライミー】を皆さんご存じでしょうか。 「自分のイメージするインテリア、本当に欲しいインテリアがどこにあるの ...

4

ついに、noteの月間アクティブユーザー数が4400万人(2020年3月時点)に到達しました。 そもそも、「note」とは、クリエイターが、文章やマンガ、写真、音声を投稿することができ、ユーザーはその ...

5

ボードゲームカフェが1日2回転で儲かるという記事をみつけたので興味を持ち、調べてみました。 まずは、需要がどれくらいあるのか、市場のようすからみていきましょう。 世界最大のボードゲーム市場はドイツで、 ...

-code, VR
-,

Copyright© BUSINESS HUNTER , 2023 All Rights Reserved Powered by AFFINGER5.