質問編集履歴
1
誤字の修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Unity Photon2 プレイヤーがルームに参加すると床をすり抜けて落下してします。
|
1
|
+
Unity Photon2 プレイヤーがルームに参加すると床をすり抜けて落下してしまいます。
|
test
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
UnityのPhoton2でゲームを再生するとプレイヤー1がルームを作り、プレイヤー2以降がそのルームに参加するプログラムを[この動画](https://www.youtube.com/watch?v=LjnFNSlUMXI&list=PL6PsTmPNvw0eZirNDjO8dL0Y6X0ZFGaMt&index=11)を参考に作ったのですが、どちらも相手プレイヤーが表示はされるのですが、スポーンしたらすぐ床をそれぞれの画面の相手プレイヤーがすり抜けて落下してしまいます。
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
```c#
|
1
|
+
UnityのPhoton2でゲームを再生するとプレイヤー1がルームを作り、プレイヤー2以降がそのルームに参加するプログラムを[この動画](https://www.youtube.com/watch?v=LjnFNSlUMXI&list=PL6PsTmPNvw0eZirNDjO8dL0Y6X0ZFGaMt&index=11)を参考に作ったのですが、どちらも相手プレイヤーが表示はされるのですが、スポーンしたらすぐ床をそれぞれの画面の相手プレイヤーが床をすり抜けて落下してしまいます。
|
2
|
+
|
3
|
+
なにが、原因でしょうか?
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
PlayerMove
|
8
|
+
|
9
|
+
```C#
|
12
10
|
|
13
11
|
using System.Collections;
|
14
12
|
|
@@ -20,29 +18,177 @@
|
|
20
18
|
|
21
19
|
|
22
20
|
|
23
|
-
public class PlayerM
|
21
|
+
public class PlayerMove : MonoBehaviourPunCallbacks
|
24
22
|
|
25
23
|
{
|
26
24
|
|
25
|
+
private CharacterController controller;
|
26
|
+
|
27
|
+
private Animator animator;
|
28
|
+
|
29
|
+
private Vector3 velocity;
|
30
|
+
|
31
|
+
[SerializeField]
|
32
|
+
|
33
|
+
private float walkSpeed = 5f;
|
34
|
+
|
35
|
+
[SerializeField]
|
36
|
+
|
37
|
+
private float runSpeed = 8f;
|
38
|
+
|
39
|
+
private bool runFlag = false;
|
40
|
+
|
41
|
+
public float mouseSensitivity = 100f;
|
42
|
+
|
43
|
+
public Transform playerBody;
|
44
|
+
|
45
|
+
float xRotation = 0f;
|
46
|
+
|
47
|
+
[SerializeField]
|
48
|
+
|
49
|
+
private Transform spine;
|
50
|
+
|
51
|
+
public GameObject cameraParent;
|
52
|
+
|
53
|
+
|
54
|
+
|
27
55
|
void Start()
|
28
56
|
|
29
57
|
{
|
30
58
|
|
59
|
+
controller = GetComponent<CharacterController>();
|
60
|
+
|
61
|
+
animator = GetComponent<Animator>();
|
62
|
+
|
63
|
+
Cursor.lockState = CursorLockMode.Locked;
|
64
|
+
|
31
65
|
if (photonView.IsMine)
|
32
66
|
|
33
67
|
{
|
34
68
|
|
69
|
+
cameraParent.SetActive(true);
|
70
|
+
|
35
|
-
|
71
|
+
controller.enabled = true;
|
36
|
-
|
72
|
+
|
37
|
-
}
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
void Update()
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
if (!photonView.IsMine) return;
|
84
|
+
|
85
|
+
if (controller.isGrounded)
|
86
|
+
|
87
|
+
{
|
88
|
+
|
89
|
+
velocity = Vector3.zero;
|
90
|
+
|
91
|
+
velocity = (transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal")).normalized;
|
92
|
+
|
93
|
+
float speed = 0f;
|
94
|
+
|
95
|
+
if ((Input.GetButton("Run")&& Input.GetButton("Fire2") == false))
|
96
|
+
|
97
|
+
{
|
98
|
+
|
99
|
+
runFlag = true;
|
100
|
+
|
101
|
+
speed = runSpeed;
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
else
|
106
|
+
|
107
|
+
{
|
108
|
+
|
109
|
+
runFlag = false;
|
110
|
+
|
111
|
+
speed = walkSpeed;
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
velocity *= speed;
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
if (velocity.magnitude > 0f)
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
if (runFlag)
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
animator.SetFloat("Speed", 2.1f);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
else
|
132
|
+
|
133
|
+
{
|
134
|
+
|
135
|
+
animator.SetFloat("Speed", 1f);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
else
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
animator.SetFloat("Speed", 0f);
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
velocity.y += Physics.gravity.y * Time.deltaTime;
|
152
|
+
|
153
|
+
controller.Move(velocity * Time.deltaTime);
|
154
|
+
|
155
|
+
if (Input.GetKey(KeyCode.Escape))
|
156
|
+
|
157
|
+
{
|
158
|
+
|
159
|
+
Application.Quit();
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
void LateUpdate()
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
if (!photonView.IsMine) return;
|
170
|
+
|
171
|
+
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
|
172
|
+
|
173
|
+
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
|
174
|
+
|
175
|
+
xRotation -= mouseY;
|
176
|
+
|
177
|
+
xRotation = Mathf.Clamp(xRotation, -90, 90);
|
178
|
+
|
179
|
+
playerBody.Rotate(Vector3.up * mouseX);
|
180
|
+
|
181
|
+
spine.rotation = Quaternion.Euler(spine.eulerAngles.x + xRotation, spine.eulerAngles.y, spine.eulerAngles.z);
|
38
182
|
|
39
183
|
}
|
40
184
|
|
41
185
|
}
|
42
186
|
|
187
|
+
|
188
|
+
|
43
189
|
```
|
44
190
|
|
45
|
-
|
191
|
+
Launcher (MenuScene)
|
46
192
|
|
47
193
|
```C#
|
48
194
|
|
@@ -56,177 +202,105 @@
|
|
56
202
|
|
57
203
|
|
58
204
|
|
59
|
-
|
205
|
+
namespace TEST
|
60
206
|
|
61
207
|
{
|
62
208
|
|
63
|
-
p
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
p
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
p
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
public
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
an
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
i
|
122
|
-
|
123
|
-
|
209
|
+
public class Launcher : MonoBehaviourPunCallbacks
|
210
|
+
|
211
|
+
{
|
212
|
+
|
213
|
+
public void Awake()
|
214
|
+
|
215
|
+
{
|
216
|
+
|
217
|
+
PhotonNetwork.AutomaticallySyncScene = true;
|
218
|
+
|
219
|
+
Connect();
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
public override void OnConnectedToMaster()
|
224
|
+
|
225
|
+
{
|
226
|
+
|
227
|
+
Debug.Log("CONNECTED");
|
228
|
+
|
229
|
+
Join();
|
230
|
+
|
231
|
+
base.OnConnectedToMaster();
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
public override void OnJoinedRoom()
|
236
|
+
|
237
|
+
{
|
238
|
+
|
239
|
+
StartGame();
|
240
|
+
|
241
|
+
base.OnJoinedRoom();
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
public override void OnJoinRandomFailed(short returnCode, string message)
|
246
|
+
|
247
|
+
{
|
248
|
+
|
249
|
+
Create();
|
250
|
+
|
251
|
+
base.OnJoinRandomFailed(returnCode, message);
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
public void Connect()
|
256
|
+
|
257
|
+
{
|
258
|
+
|
259
|
+
Debug.Log("Trying to Connect");
|
260
|
+
|
261
|
+
PhotonNetwork.GameVersion = "0.0.0";
|
262
|
+
|
263
|
+
PhotonNetwork.ConnectUsingSettings();
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
public void Join()
|
268
|
+
|
269
|
+
{
|
270
|
+
|
271
|
+
PhotonNetwork.JoinRandomRoom();
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
public void Create()
|
276
|
+
|
277
|
+
{
|
278
|
+
|
279
|
+
PhotonNetwork.CreateRoom("");
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
public void StartGame()
|
284
|
+
|
285
|
+
{
|
286
|
+
|
287
|
+
if(PhotonNetwork.CurrentRoom.PlayerCount == 1)
|
124
288
|
|
125
289
|
{
|
126
290
|
|
127
|
-
velocity = Vector3.zero;
|
128
|
-
|
129
|
-
velocity = (transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal")).normalized;
|
130
|
-
|
131
|
-
float speed = 0f;
|
132
|
-
|
133
|
-
if ((Input.GetButton("Run")&& Input.GetButton("Fire2") == false))
|
134
|
-
|
135
|
-
{
|
136
|
-
|
137
|
-
runFlag = true;
|
138
|
-
|
139
|
-
speed = runSpeed;
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
else
|
144
|
-
|
145
|
-
{
|
146
|
-
|
147
|
-
runFlag = false;
|
148
|
-
|
149
|
-
speed = walkSpeed;
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
velocity *= speed;
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
if (velocity.magnitude > 0f)
|
158
|
-
|
159
|
-
{
|
160
|
-
|
161
|
-
if (runFlag)
|
162
|
-
|
163
|
-
{
|
164
|
-
|
165
|
-
animator.SetFloat("Speed", 2.1f);
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
else
|
170
|
-
|
171
|
-
{
|
172
|
-
|
173
|
-
|
291
|
+
PhotonNetwork.LoadLevel(1);
|
174
|
-
|
175
|
-
}
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
else
|
180
|
-
|
181
|
-
{
|
182
|
-
|
183
|
-
animator.SetFloat("Speed", 0f);
|
184
|
-
|
185
|
-
}
|
186
292
|
|
187
293
|
}
|
188
294
|
|
189
|
-
velocity.y += Physics.gravity.y * Time.deltaTime;
|
190
|
-
|
191
|
-
controller.Move(velocity * Time.deltaTime);
|
192
|
-
|
193
|
-
if (Input.GetKey(KeyCode.Escape))
|
194
|
-
|
195
|
-
{
|
196
|
-
|
197
|
-
Application.Quit();
|
198
|
-
|
199
|
-
}
|
295
|
+
}
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
void LateUpdate()
|
204
|
-
|
205
|
-
{
|
206
|
-
|
207
|
-
if (!photonView.IsMine) return;
|
208
|
-
|
209
|
-
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
|
210
|
-
|
211
|
-
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
|
212
|
-
|
213
|
-
xRotation -= mouseY;
|
214
|
-
|
215
|
-
xRotation = Mathf.Clamp(xRotation, -90, 90);
|
216
|
-
|
217
|
-
playerBody.Rotate(Vector3.up * mouseX);
|
218
|
-
|
219
|
-
spine.rotation = Quaternion.Euler(spine.eulerAngles.x + xRotation, spine.eulerAngles.y, spine.eulerAngles.z);
|
220
296
|
|
221
297
|
}
|
222
298
|
|
223
299
|
}
|
224
300
|
|
225
|
-
|
226
|
-
|
227
301
|
```
|
228
302
|
|
229
|
-
|
303
|
+
Manager (MapScene)
|
230
304
|
|
231
305
|
```C#
|
232
306
|
|
@@ -244,91 +318,25 @@
|
|
244
318
|
|
245
319
|
{
|
246
320
|
|
247
|
-
public class
|
321
|
+
public class Manager : MonoBehaviour
|
248
|
-
|
322
|
+
|
249
|
-
{
|
323
|
+
{
|
324
|
+
|
250
|
-
|
325
|
+
public Transform spawn_point;
|
326
|
+
|
251
|
-
p
|
327
|
+
private void Start()
|
252
|
-
|
328
|
+
|
253
|
-
{
|
329
|
+
{
|
254
|
-
|
255
|
-
|
330
|
+
|
256
|
-
|
257
|
-
|
331
|
+
Spawn();
|
258
|
-
|
332
|
+
|
259
|
-
}
|
333
|
+
}
|
260
|
-
|
334
|
+
|
261
|
-
public
|
335
|
+
public void Spawn()
|
262
|
-
|
336
|
+
|
263
|
-
{
|
337
|
+
{
|
264
|
-
|
265
|
-
|
338
|
+
|
266
|
-
|
267
|
-
Join();
|
268
|
-
|
269
|
-
base.OnConnectedToMaster();
|
270
|
-
|
271
|
-
}
|
272
|
-
|
273
|
-
public override void OnJoinedRoom()
|
274
|
-
|
275
|
-
{
|
276
|
-
|
277
|
-
StartGame();
|
278
|
-
|
279
|
-
base.OnJoinedRoom();
|
280
|
-
|
281
|
-
}
|
282
|
-
|
283
|
-
|
339
|
+
GameObject Player = PhotonNetwork.Instantiate("Pose",spawn_point.position,spawn_point.rotation);
|
284
|
-
|
285
|
-
{
|
286
|
-
|
287
|
-
Create();
|
288
|
-
|
289
|
-
base.OnJoinRandomFailed(returnCode, message);
|
290
|
-
|
291
|
-
}
|
292
|
-
|
293
|
-
public void Connect()
|
294
|
-
|
295
|
-
{
|
296
|
-
|
297
|
-
Debug.Log("Trying to Connect");
|
298
|
-
|
299
|
-
PhotonNetwork.GameVersion = "0.0.0";
|
300
|
-
|
301
|
-
PhotonNetwork.ConnectUsingSettings();
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
public void Join()
|
306
|
-
|
307
|
-
{
|
308
|
-
|
309
|
-
PhotonNetwork.JoinRandomRoom();
|
310
|
-
|
311
|
-
}
|
312
|
-
|
313
|
-
public void Create()
|
314
|
-
|
315
|
-
{
|
316
|
-
|
317
|
-
PhotonNetwork.CreateRoom("");
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
public void StartGame()
|
322
|
-
|
323
|
-
{
|
324
|
-
|
325
|
-
if(PhotonNetwork.CurrentRoom.PlayerCount == 1)
|
326
|
-
|
327
|
-
{
|
328
|
-
|
329
|
-
PhotonNetwork.LoadLevel(1);
|
330
|
-
|
331
|
-
}
|
332
340
|
|
333
341
|
}
|
334
342
|
|
@@ -337,49 +345,3 @@
|
|
337
345
|
}
|
338
346
|
|
339
347
|
```
|
340
|
-
|
341
|
-
Manager (MapScene)
|
342
|
-
|
343
|
-
```C#
|
344
|
-
|
345
|
-
using System.Collections;
|
346
|
-
|
347
|
-
using System.Collections.Generic;
|
348
|
-
|
349
|
-
using UnityEngine;
|
350
|
-
|
351
|
-
using Photon.Pun;
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
namespace TEST
|
356
|
-
|
357
|
-
{
|
358
|
-
|
359
|
-
public class Manager : MonoBehaviour
|
360
|
-
|
361
|
-
{
|
362
|
-
|
363
|
-
public Transform spawn_point;
|
364
|
-
|
365
|
-
private void Start()
|
366
|
-
|
367
|
-
{
|
368
|
-
|
369
|
-
Spawn();
|
370
|
-
|
371
|
-
}
|
372
|
-
|
373
|
-
public void Spawn()
|
374
|
-
|
375
|
-
{
|
376
|
-
|
377
|
-
GameObject Player = PhotonNetwork.Instantiate("Pose",spawn_point.position,spawn_point.rotation);
|
378
|
-
|
379
|
-
}
|
380
|
-
|
381
|
-
}
|
382
|
-
|
383
|
-
}
|
384
|
-
|
385
|
-
```
|