teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

エラーについて追加

2019/07/05 09:39

投稿

hoheinabachan
hoheinabachan

スコア6

title CHANGED
File without changes
body CHANGED
@@ -6,6 +6,10 @@
6
6
 
7
7
  先輩からの引継ぎで、今は直接質問できないのでここで質問させていただきます。どこに問題があるのか見当がつかないのでとりあえず直接関わりがありそうなコードを貼りました。判断材料が足りないようでしたら適宜追加します。どうぞよろしくお願いいたします。
8
8
 
9
+ このようなエラーも出ます。Vector3が問題なのはわかるのですが…
10
+ NullReferenceException: Object reference not set to an instance of an object
11
+ RiggedFinger.Update () (at Assets/LeapMotion/Scripts/Hands/RiggedFinger.cs:77)
12
+
9
13
  ```C#
10
14
  using UnityEngine;
11
15
  using System.Collections;
@@ -192,10 +196,9 @@
192
196
 
193
197
 
194
198
 
195
- //palm.LookAt(palm, GetPalmNormal());
199
+
196
200
  Vector3 stop = new Vector3(palm.position.x, palm.position.y, palm.position.z);
197
- //Vector3 newStop = transform.TransformPoint(palm.position.x+alpha, palm.position.y, palm.position.z);
201
+
198
- //Vector3 newStop = GetPalmNormal();
199
202
  Quaternion stop1 = GetPalmRotation() * Reorientation();
200
203
  Quaternion stop2 = GetArmRotation() * Reorientation();
201
204
  stop1 = Quaternion.Euler(0, -85, 190);

1

コード追加

2019/07/05 09:39

投稿

hoheinabachan
hoheinabachan

スコア6

title CHANGED
File without changes
body CHANGED
@@ -4,9 +4,78 @@
4
4
 
5
5
  Oculus Riftを起動していない状態でUnityを動かすとGameビュー上では想定通りの動作をしていて問題ないのですが、Oculus Riftを起動した状態だとキーを押しても動きません(例えばF4を押しても動くときと動かない時がある)。
6
6
 
7
- 先輩からの引継ぎで、今は直接質問できないのでここで質問させていただきます。どこに問題があるのか見当がつかないのでとりあえず直接関わりがありそうなコードを1つ貼りました。判断材料が足りないようでしたら適宜追加します。どうぞよろしくお願いいたします。
7
+ 先輩からの引継ぎで、今は直接質問できないのでここで質問させていただきます。どこに問題があるのか見当がつかないのでとりあえず直接関わりがありそうなコードを貼りました。判断材料が足りないようでしたら適宜追加します。どうぞよろしくお願いいたします。
8
8
 
9
9
  ```C#
10
+ using UnityEngine;
11
+ using System.Collections;
12
+ using Leap;
13
+
14
+ public class RiggedFinger : FingerModel
15
+ {
16
+ public bool deformPosition = false;
17
+
18
+ public Vector3 modelFingerPointing = Vector3.forward;
19
+ public Vector3 modelPalmFacing = -Vector3.up;
20
+ private GameObject centerObj;
21
+
22
+ public Quaternion Reorientation()
23
+ {
24
+ return Quaternion.Inverse(Quaternion.LookRotation(modelFingerPointing, -modelPalmFacing));
25
+ }
26
+
27
+ /** Updates the bone rotations. */
28
+ public override void UpdateFinger()
29
+ {
30
+ for (int i = 0; i < bones.Length; ++i)
31
+ {
32
+ if (bones[i] != null)
33
+ {
34
+ bones[i].rotation = GetBoneRotation(i) * Reorientation();
35
+ if (deformPosition)
36
+ {
37
+ bones[i].position = GetBoneCenter(i);
38
+ }
39
+ }
40
+ }
41
+ }
42
+ private void Start()
43
+ {
44
+ print("2");
45
+ centerObj = GameObject.Find("Brush1"); //試しのコメントアウト
46
+
47
+ centerObj.transform.position = new Vector3(centerObj.transform.position.x, centerObj.transform.position.y, centerObj.transform.position.z);
48
+ }
49
+ public void Update()
50
+ {
51
+ Hand righthand = GetLeapHand();
52
+ //print(111);
53
+
54
+ if (righthand.IsRight)
55
+ {
56
+ Finger finger = GetLeapFinger();
57
+ Finger.FingerType fType = fingerType;
58
+ if (fType == Finger.FingerType.TYPE_INDEX)
59
+ {
60
+ Vector3 pencilposition = this.bones[3].position;
61
+
62
+ Quaternion pencilrotation = GetBoneRotation(3) * Reorientation();
63
+ pencilrotation = Quaternion.Euler(20, 0, 80);
64
+
65
+
66
+ Vector3 position = this.centerObj.transform.position;
67
+ centerObj.transform.position = new Vector3(pencilposition.x, pencilposition.y, pencilposition.z);
68
+ centerObj.transform.rotation = new Quaternion(pencilrotation.w, pencilrotation.x, pencilrotation.y, pencilrotation.z);
69
+ }
70
+ }
71
+
72
+
73
+ }
74
+
75
+ }
76
+ ```
77
+
78
+ ```C#
10
79
  RiggedHand.cs
11
80
  using UnityEngine;
12
81
  using System.Collections;