質問編集履歴
1
キャラクターの移動に使っている部分のスクリプトを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,9 +10,177 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
|
13
|
+
### 該当のソースコード
|
14
|
+
|
14
|
-
|
15
|
+
キャラクターの移動に使っている部分です。
|
16
|
+
|
17
|
+
|
18
|
+
|
15
|
-
|
19
|
+
```
|
20
|
+
|
21
|
+
public PhotonView photonView;
|
22
|
+
|
23
|
+
public PhotonTransformView photonTransformView;
|
24
|
+
|
25
|
+
public Animator animator;
|
26
|
+
|
27
|
+
public CharacterController chCon;
|
28
|
+
|
29
|
+
public float speed;
|
30
|
+
|
31
|
+
public float jumpspeed;
|
32
|
+
|
33
|
+
public float rotatespeed;
|
34
|
+
|
35
|
+
public float gravity;
|
36
|
+
|
37
|
+
public int moveLock;
|
38
|
+
|
39
|
+
Vector3 targetDirection;
|
40
|
+
|
41
|
+
Vector3 moveDirection;
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
void Update()
|
46
|
+
|
47
|
+
{
|
48
|
+
|
49
|
+
if (!photonView.isMine)
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
return;
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
if (movelock <= 0)
|
60
|
+
|
61
|
+
{
|
62
|
+
|
63
|
+
MoveControl();
|
64
|
+
|
65
|
+
RotationControl();
|
66
|
+
|
67
|
+
chCon.Move(moveDirection * Time.deltaTime);
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
Vector3 velocity = chCon.velocity;
|
74
|
+
|
75
|
+
photonTransformView.SetSynchronizedValues(velocity, 0);
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
void MoveControl()
|
84
|
+
|
85
|
+
{
|
86
|
+
|
87
|
+
float v = Input.GetAxisRaw("Vertical");
|
88
|
+
|
89
|
+
float h = Input.GetAxisRaw("Horizontal");
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
Vector3 forword = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1));
|
94
|
+
|
95
|
+
Vector3 right = Camera.main.transform.right;
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
targetDirection = h * right + v * forword;
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
if (chCon.isGrounded)
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
moveDirection = targetDirection * speed;
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
if (Input.GetButtonDown("Jump"))
|
112
|
+
|
113
|
+
{
|
114
|
+
|
115
|
+
moveDirection.y = jumpspeed;
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
else
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
float tempy = moveDirection.y;
|
128
|
+
|
129
|
+
moveDirection.y = tempy - gravity * Time.deltaTime;
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
if(v>.1 || v<-.1 || h>.1 || h < -.1)
|
136
|
+
|
137
|
+
{
|
138
|
+
|
139
|
+
animator.SetFloat("Speed", 1f);
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
else
|
144
|
+
|
145
|
+
{
|
146
|
+
|
147
|
+
animator.SetFloat("Speed", 0f);
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
void RotationControl()
|
160
|
+
|
161
|
+
{
|
162
|
+
|
163
|
+
Vector3 rotateDirection = moveDirection;
|
164
|
+
|
165
|
+
rotateDirection.y = 0;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
if(rotateDirection.sqrMagnitude > 0.01)
|
170
|
+
|
171
|
+
{
|
172
|
+
|
173
|
+
float step = rotatespeed * Time.deltaTime;
|
174
|
+
|
175
|
+
Vector3 newDir = Vector3.Slerp(transform.forward, rotateDirection, step);
|
176
|
+
|
177
|
+
transform.rotation = Quaternion.LookRotation(newDir);
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
```
|
16
184
|
|
17
185
|
|
18
186
|
|