回答編集履歴
4
Quaternion.LookRotation
test
CHANGED
@@ -72,7 +72,7 @@
|
|
72
72
|
|
73
73
|
Vector3 dir=Camera.main.tranform.rotation*delta;
|
74
74
|
|
75
|
-
target.transform.rotation=Qua
|
75
|
+
target.transform.rotation=Quaternion.LookRotation(dir);
|
76
76
|
|
77
77
|
lastPos=p;
|
78
78
|
|
@@ -114,7 +114,7 @@
|
|
114
114
|
|
115
115
|
Vector3 dir=Camera.main.tranform.rotation*delta;
|
116
116
|
|
117
|
-
q=Qua
|
117
|
+
q=Quaternion.LookRotation(dir);
|
118
118
|
|
119
119
|
lastPos=p;
|
120
120
|
|
3
追記
test
CHANGED
@@ -32,21 +32,109 @@
|
|
32
32
|
|
33
33
|
Vector3 axis=Camera.main.tranform.rotation*normal;
|
34
34
|
|
35
|
-
|
35
|
+
target.transform.rotation*=Quarternion.AngleAxis(delta.magnitude,axis.normalized);
|
36
|
-
|
36
|
+
|
37
|
-
lastPos=p;
|
37
|
+
lastPos=p;
|
38
|
-
|
38
|
+
|
39
|
-
}
|
39
|
+
}
|
40
|
-
|
40
|
+
|
41
|
-
}
|
41
|
+
}
|
42
|
-
|
42
|
+
|
43
|
-
}
|
43
|
+
}
|
44
|
-
|
44
|
+
|
45
|
-
```
|
45
|
+
```
|
46
|
+
|
46
|
-
|
47
|
+
向かせるプログラム
|
48
|
+
|
47
|
-
|
49
|
+
```c#
|
50
|
+
|
48
|
-
|
51
|
+
public class SwipeLookAt:MonoBehavior{
|
52
|
+
|
49
|
-
|
53
|
+
public GameObject target;
|
54
|
+
|
55
|
+
Vector3 lastPos;
|
56
|
+
|
57
|
+
void Update(){
|
58
|
+
|
59
|
+
p=Input.mousePosition;
|
60
|
+
|
61
|
+
if(Input.GetMouseButtonDown(0)){
|
62
|
+
|
63
|
+
lastPos=p;
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
else if(Input.GetMouseButton(0)){
|
68
|
+
|
69
|
+
Vector3 delta=p-lastPos;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
Vector3 dir=Camera.main.tranform.rotation*delta;
|
74
|
+
|
75
|
+
target.transform.rotation=Quarternion.LookAt(dir);
|
76
|
+
|
77
|
+
lastPos=p;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
線形補完付き
|
88
|
+
|
89
|
+
```c#
|
90
|
+
|
91
|
+
public class SwipeLookAt:MonoBehavior{
|
92
|
+
|
93
|
+
public GameObject target;
|
94
|
+
|
95
|
+
Vector3 lastPos;
|
96
|
+
|
97
|
+
Quarternion q;
|
98
|
+
|
99
|
+
void Update(){
|
100
|
+
|
101
|
+
p=Input.mousePosition;
|
102
|
+
|
103
|
+
if(Input.GetMouseButtonDown(0)){
|
104
|
+
|
105
|
+
lastPos=p;
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
else if(Input.GetMouseButton(0)){
|
110
|
+
|
111
|
+
Vector3 delta=p-lastPos;
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
Vector3 dir=Camera.main.tranform.rotation*delta;
|
116
|
+
|
117
|
+
q=Quarternion.LookAt(dir);
|
118
|
+
|
119
|
+
lastPos=p;
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
target.transform.rotation=Quarternion.Lerp(target.transform.rotation,q,Time.deltaTime);
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
おまけ
|
50
138
|
|
51
139
|
3D空間上で納得できる移動にする方法を幾つか挙げておきます。
|
52
140
|
|
2
回転のプログラムを追記
test
CHANGED
@@ -1,4 +1,50 @@
|
|
1
1
|
質問頂きありがとうございます。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
追記
|
6
|
+
|
7
|
+
回転のプログラム
|
8
|
+
|
9
|
+
```c#
|
10
|
+
|
11
|
+
public class SwipeRotate:MonoBehavior{
|
12
|
+
|
13
|
+
public GameObject target;
|
14
|
+
|
15
|
+
Vector3 lastPos;
|
16
|
+
|
17
|
+
void Update(){
|
18
|
+
|
19
|
+
p=Input.mousePosition;
|
20
|
+
|
21
|
+
if(Input.GetMouseButtonDown(0)){
|
22
|
+
|
23
|
+
lastPos=p;
|
24
|
+
|
25
|
+
}
|
26
|
+
|
27
|
+
else if(Input.GetMouseButton(0)){
|
28
|
+
|
29
|
+
Vector3 delta=p-lastPos;
|
30
|
+
|
31
|
+
Vector3 normal=Quarternion.Euler(0,0,90)*delta;
|
32
|
+
|
33
|
+
Vector3 axis=Camera.main.tranform.rotation*normal;
|
34
|
+
|
35
|
+
Camera.main.transform.rotation*=Quarternion.AngleAxis(delta.magnitude,axis.normalized);
|
36
|
+
|
37
|
+
lastPos=p;
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
|
2
48
|
|
3
49
|
|
4
50
|
|
1
取りあえずエラーを直しました
test
CHANGED
@@ -74,7 +74,7 @@
|
|
74
74
|
|
75
75
|
void Update(){
|
76
76
|
|
77
|
-
Vector3 p=Camera.main.ScreenToWorldPoint(Input.mousePosition.x,Input.mousePosition.y,Vector3.Distance(target.transform.position,Camera.main.transform.position));
|
77
|
+
Vector3 p=Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,Vector3.Distance(target.transform.position,Camera.main.transform.position))));
|
78
78
|
|
79
79
|
if(Input.GetMouseButtonDown(0)){
|
80
80
|
|