質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

2571閲覧

PS4コントローラーで視点を移動させたい

Unity_ichigo

総合スコア23

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2019/06/29 17:11

編集2019/06/29 17:13

前提・実現したいこと

Unityでホラーゲームを開発しています
プレイヤーはStandardAsset内の「FPSController」をそのまま使っています
現在、PS4のコントローラ-で移動はできるのですが
視点移動ができません
いくつものサイトを見ましたが駄目でした

該当のソースコード

C#

1using System; 2using UnityEngine; 3using UnityStandardAssets.CrossPlatformInput; 4 5namespace UnityStandardAssets.Characters.FirstPerson 6{ 7 [Serializable] 8 public class MouseLook 9 { 10 public float XSensitivity = 2f; 11 public float YSensitivity = 2f; 12 public bool clampVerticalRotation = true; 13 public float MinimumX = -90F; 14 public float MaximumX = 90F; 15 public bool smooth; 16 public float smoothTime = 5f; 17 public bool lockCursor = true; 18 19 20 private Quaternion m_CharacterTargetRot; 21 private Quaternion m_CameraTargetRot; 22 private bool m_cursorIsLocked = true; 23 24 public void Init(Transform character, Transform camera) 25 { 26 m_CharacterTargetRot = character.localRotation; 27 m_CameraTargetRot = camera.localRotation; 28 } 29 30 31 public void LookRotation(Transform character, Transform camera) 32 { 33 float yRot = CrossPlatformInputManager.GetAxis("Mouse X") * XSensitivity; 34 float xRot = CrossPlatformInputManager.GetAxis("Mouse Y") * YSensitivity; 35 36 m_CharacterTargetRot *= Quaternion.Euler (0f, yRot, 0f); 37 m_CameraTargetRot *= Quaternion.Euler (-xRot, 0f, 0f); 38 39 if(clampVerticalRotation) 40 m_CameraTargetRot = ClampRotationAroundXAxis (m_CameraTargetRot); 41 42 if(smooth) 43 { 44 character.localRotation = Quaternion.Slerp (character.localRotation, m_CharacterTargetRot, 45 smoothTime * Time.deltaTime); 46 camera.localRotation = Quaternion.Slerp (camera.localRotation, m_CameraTargetRot, 47 smoothTime * Time.deltaTime); 48 } 49 else 50 { 51 character.localRotation = m_CharacterTargetRot; 52 camera.localRotation = m_CameraTargetRot; 53 } 54 55 UpdateCursorLock(); 56 } 57 58 public void SetCursorLock(bool value) 59 { 60 lockCursor = value; 61 if(!lockCursor) 62 {//we force unlock the cursor if the user disable the cursor locking helper 63 Cursor.lockState = CursorLockMode.None; 64 Cursor.visible = true; 65 } 66 } 67 68 public void UpdateCursorLock() 69 { 70 //if the user set "lockCursor" we check & properly lock the cursos 71 if (lockCursor) 72 InternalLockUpdate(); 73 } 74 75 private void InternalLockUpdate() 76 { 77 if(Input.GetKeyUp(KeyCode.Escape)) 78 { 79 m_cursorIsLocked = false; 80 } 81 else if(Input.GetMouseButtonUp(0)) 82 { 83 m_cursorIsLocked = true; 84 } 85 86 if (m_cursorIsLocked) 87 { 88 Cursor.lockState = CursorLockMode.Locked; 89 Cursor.visible = false; 90 } 91 else if (!m_cursorIsLocked) 92 { 93 Cursor.lockState = CursorLockMode.None; 94 Cursor.visible = true; 95 } 96 } 97 98 Quaternion ClampRotationAroundXAxis(Quaternion q) 99 { 100 q.x /= q.w; 101 q.y /= q.w; 102 q.z /= q.w; 103 q.w = 1.0f; 104 105 float angleX = 2.0f * Mathf.Rad2Deg * Mathf.Atan (q.x); 106 107 angleX = Mathf.Clamp (angleX, MinimumX, MaximumX); 108 109 q.x = Mathf.Tan (0.5f * Mathf.Deg2Rad * angleX); 110 111 return q; 112 } 113 114 } 115} 116

試したこと

以下のサイト様では解決しませんでした
https://qiita.com/o_s_t/items/c18edeeee869d42c6eb9
https://qiita.com/fujita06/items/b6a829b2741c2c926f7c
https://younaship.com/2019/01/29/unity%E3%81%A7ps4%E3%81%AE%E3%82%B3%E3%83%B3%E3%83%88%E3%83%AD%E3%83%BC%E3%83%A9%E3%83%BC%E3%82%92%E4%BD%BF%E3%81%86%E6%96%B9%E6%B3%95/
http://nn-hokuson.hatenablog.com/entry/2017/11/20/211617
http://kurogomapurin.hatenablog.com/entry/2015/10/13/215330
http://yun.cup.com/unity041.html

補足情報(FW/ツールのバージョンなど)

Unity2018

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Bongo

2019/06/29 18:48

ご提示のおもちゃラボさんで紹介されている「Controller Tester」もすでにお試しでしょうか。 その際の結果はどうだったでしょうか。移動ができたということは移動用スティックは応答するかと思うのですが、視点操作用スティックの様子はどうでしょうか?
Unity_ichigo

2019/06/30 06:11 編集

両方のスティックちゃんと動作しました!
guest

回答1

0

自己解決

キー設定で
CON XとCON Yを作成して

C#

1 public void LookRotation(Transform character, Transform camera) 2 { 3 float yRot = CrossPlatformInputManager.GetAxis("Mouse X") * XSensitivity; 4 float xRot = CrossPlatformInputManager.GetAxis("Mouse Y") * YSensitivity; 5 6 var controllerNames = Input.GetJoystickNames(); 7 if (controllerNames[0] != "") 8 { 9 xRot = 0; 10 yRot = 0; 11 yRot = Input.GetAxis("CON X") * XSensitivity; 12 xRot = Input.GetAxis("CON Y") * YSensitivity; 13 } 14 15 m_CharacterTargetRot *= Quaternion.Euler (0f, yRot, 0f); 16 m_CameraTargetRot *= Quaternion.Euler (-xRot, 0f, 0f); 17 18 if(clampVerticalRotation) 19 m_CameraTargetRot = ClampRotationAroundXAxis (m_CameraTargetRot); 20 21 if(smooth) 22 { 23 character.localRotation = Quaternion.Slerp (character.localRotation, m_CharacterTargetRot, 24 smoothTime * Time.deltaTime); 25 camera.localRotation = Quaternion.Slerp (camera.localRotation, m_CameraTargetRot, 26 smoothTime * Time.deltaTime); 27 } 28 else 29 { 30 character.localRotation = m_CharacterTargetRot; 31 camera.localRotation = m_CameraTargetRot; 32 } 33 34 UpdateCursorLock(); 35 }

このようにしたらできました!

投稿2019/06/30 06:30

Unity_ichigo

総合スコア23

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問