Skip to content

Commit 9cebe9e

Browse files
authored
Merge pull request #66 from idesemi-weekly/v0_1_1
fixed dino game issues, less latency and fixed UDP transport
2 parents e5c65c9 + 6f2e005 commit 9cebe9e

19 files changed

+139
-229
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
# Visual Studio cache directory
2727
.vs/
28+
.vscode/
2829

2930
# Gradle cache directory
3031
.gradle/

.plastic/plastic.changes

-440 Bytes
Binary file not shown.

.plastic/plastic.wktree

-448 Bytes
Binary file not shown.

Assets/Prefabs/NetworkPlayer.prefab

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ Transform:
349349
serializedVersion: 2
350350
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
351351
m_LocalPosition: {x: 0, y: 0, z: 0}
352-
m_LocalScale: {x: 1, y: 1, z: 1}
353-
m_ConstrainProportionsScale: 0
352+
m_LocalScale: {x: 0, y: 0, z: 0}
353+
m_ConstrainProportionsScale: 1
354354
m_Children:
355355
- {fileID: 3492141313273106099}
356356
- {fileID: 8979871998478862501}
@@ -369,7 +369,7 @@ MonoBehaviour:
369369
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
370370
m_Name:
371371
m_EditorClassIdentifier:
372-
GlobalObjectIdHash: 2275888324
372+
GlobalObjectIdHash: 2663830612
373373
InScenePlacedSourceGlobalObjectIdHash: 2275888324
374374
AlwaysReplicateAsRoot: 0
375375
SynchronizeTransform: 1
@@ -2351,6 +2351,18 @@ PrefabInstance:
23512351
serializedVersion: 3
23522352
m_TransformParent: {fileID: 6647573437513321787}
23532353
m_Modifications:
2354+
- target: {fileID: -8679921383154817045, guid: 8398a23740d869541a68e236f10745ee, type: 3}
2355+
propertyPath: m_LocalScale.x
2356+
value: 1
2357+
objectReference: {fileID: 0}
2358+
- target: {fileID: -8679921383154817045, guid: 8398a23740d869541a68e236f10745ee, type: 3}
2359+
propertyPath: m_LocalScale.y
2360+
value: 1
2361+
objectReference: {fileID: 0}
2362+
- target: {fileID: -8679921383154817045, guid: 8398a23740d869541a68e236f10745ee, type: 3}
2363+
propertyPath: m_LocalScale.z
2364+
value: 1
2365+
objectReference: {fileID: 0}
23542366
- target: {fileID: -8679921383154817045, guid: 8398a23740d869541a68e236f10745ee, type: 3}
23552367
propertyPath: m_LocalPosition.x
23562368
value: 0
@@ -2391,10 +2403,18 @@ PrefabInstance:
23912403
propertyPath: m_LocalEulerAnglesHint.z
23922404
value: 0
23932405
objectReference: {fileID: 0}
2406+
- target: {fileID: -8679921383154817045, guid: 8398a23740d869541a68e236f10745ee, type: 3}
2407+
propertyPath: m_ConstrainProportionsScale
2408+
value: 1
2409+
objectReference: {fileID: 0}
23942410
- target: {fileID: 919132149155446097, guid: 8398a23740d869541a68e236f10745ee, type: 3}
23952411
propertyPath: m_Name
23962412
value: RightHand
23972413
objectReference: {fileID: 0}
2414+
- target: {fileID: 919132149155446097, guid: 8398a23740d869541a68e236f10745ee, type: 3}
2415+
propertyPath: m_IsActive
2416+
value: 1
2417+
objectReference: {fileID: 0}
23982418
m_RemovedComponents: []
23992419
m_RemovedGameObjects: []
24002420
m_AddedGameObjects: []
@@ -2457,6 +2477,18 @@ PrefabInstance:
24572477
serializedVersion: 3
24582478
m_TransformParent: {fileID: 6647573437513321787}
24592479
m_Modifications:
2480+
- target: {fileID: -8679921383154817045, guid: 78b32f36a8925ce4eac1689a318ba0ff, type: 3}
2481+
propertyPath: m_LocalScale.x
2482+
value: 1
2483+
objectReference: {fileID: 0}
2484+
- target: {fileID: -8679921383154817045, guid: 78b32f36a8925ce4eac1689a318ba0ff, type: 3}
2485+
propertyPath: m_LocalScale.y
2486+
value: 1
2487+
objectReference: {fileID: 0}
2488+
- target: {fileID: -8679921383154817045, guid: 78b32f36a8925ce4eac1689a318ba0ff, type: 3}
2489+
propertyPath: m_LocalScale.z
2490+
value: 1
2491+
objectReference: {fileID: 0}
24602492
- target: {fileID: -8679921383154817045, guid: 78b32f36a8925ce4eac1689a318ba0ff, type: 3}
24612493
propertyPath: m_LocalPosition.x
24622494
value: 0
@@ -2497,10 +2529,18 @@ PrefabInstance:
24972529
propertyPath: m_LocalEulerAnglesHint.z
24982530
value: 0
24992531
objectReference: {fileID: 0}
2532+
- target: {fileID: -8679921383154817045, guid: 78b32f36a8925ce4eac1689a318ba0ff, type: 3}
2533+
propertyPath: m_ConstrainProportionsScale
2534+
value: 1
2535+
objectReference: {fileID: 0}
25002536
- target: {fileID: 919132149155446097, guid: 78b32f36a8925ce4eac1689a318ba0ff, type: 3}
25012537
propertyPath: m_Name
25022538
value: LeftHand
25032539
objectReference: {fileID: 0}
2540+
- target: {fileID: 919132149155446097, guid: 78b32f36a8925ce4eac1689a318ba0ff, type: 3}
2541+
propertyPath: m_IsActive
2542+
value: 1
2543+
objectReference: {fileID: 0}
25042544
m_RemovedComponents: []
25052545
m_RemovedGameObjects: []
25062546
m_AddedGameObjects: []

Assets/Scenes/Main Lobby.unity

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ MonoBehaviour:
16151615
m_Name:
16161616
m_EditorClassIdentifier:
16171617
maxConnection: 3
1618-
transport: {fileID: 0}
1618+
transport: {fileID: 568332004}
16191619
--- !u!1 &602859959
16201620
GameObject:
16211621
m_ObjectHideFlags: 0
@@ -4491,6 +4491,10 @@ PrefabInstance:
44914491
propertyPath: m_FacingEntered.m_PersistentCalls.m_Calls.Array.data[4].m_Target
44924492
value:
44934493
objectReference: {fileID: 0}
4494+
- target: {fileID: 4452986827867940180, guid: 65eb6b98091a5734ba9d9ca871cef69a, type: 3}
4495+
propertyPath: m_IsActive
4496+
value: 0
4497+
objectReference: {fileID: 0}
44944498
- target: {fileID: 4592956391713993908, guid: 65eb6b98091a5734ba9d9ca871cef69a, type: 3}
44954499
propertyPath: m_Name
44964500
value: Complete XR Origin Set Up Variant

Assets/Scripts/DinoScripts/Player_1.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@
55
public class Player1 : NetworkBehaviour
66
{
77
private CharacterController character;
8-
private Vector3 direction;
8+
private Vector3 velocity;
99
public InputActionReference jumpAction;
1010

1111
public float gravity = 19.62f;
1212
public float jumpForce = 8f;
1313

14+
// Add a NetworkVariable for position
15+
private NetworkVariable<Vector3> netPosition = new NetworkVariable<Vector3>();
16+
1417
private void Awake()
1518
{
1619
character = GetComponent<CharacterController>();
1720
}
1821

1922
private void OnEnable()
2023
{
21-
direction = Vector3.zero;
24+
velocity = Vector3.zero;
2225
jumpAction.action.Enable();
2326
}
2427

@@ -27,46 +30,47 @@ private void OnDisable()
2730
jumpAction.action.Disable();
2831
}
2932

30-
private void Update()
33+
public override void OnNetworkSpawn()
3134
{
32-
if (!IsServer)
35+
if (IsServer)
3336
{
34-
return;
37+
netPosition.Value = transform.position;
3538
}
36-
MovementServerRpc();
3739
}
3840

39-
[ServerRpc]
40-
private void MovementServerRpc()
41+
private void Update()
4142
{
42-
direction += Vector3.down * gravity * Time.deltaTime;
43-
44-
if (character.isGrounded && jumpAction.action.triggered)
43+
if (IsServer)
4544
{
46-
direction = Vector3.up * jumpForce;
45+
HandleMovement();
46+
}
47+
else
48+
{
49+
// Clients update their position based on the NetworkVariable
50+
transform.position = netPosition.Value;
4751
}
48-
49-
character.Move(direction * Time.deltaTime);
50-
51-
UpdateClientRpc(direction);
5252
}
5353

54-
[ClientRpc]
55-
private void UpdateClientRpc(Vector3 serverDirection)
54+
private void HandleMovement()
5655
{
57-
// Update position on clients
58-
if (!IsServer)
56+
velocity += Vector3.down * gravity * Time.deltaTime;
57+
58+
if (character.isGrounded && jumpAction.action.triggered)
5959
{
60-
character.Move(serverDirection * Time.deltaTime);
60+
velocity = Vector3.up * jumpForce;
6161
}
62+
63+
character.Move(velocity * Time.deltaTime);
64+
65+
// Update the NetworkVariable with the new position
66+
netPosition.Value = transform.position;
6267
}
6368

6469
private void OnTriggerEnter(Collider other)
6570
{
66-
6771
if (other.CompareTag("ObstacleCollision"))
6872
{
6973
GameManager.Instance.GameOver(1);
7074
}
7175
}
72-
}
76+
}

Assets/Scripts/DinoScripts/Player_2.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@
55
public class Player2 : NetworkBehaviour
66
{
77
private CharacterController character;
8-
private Vector3 direction;
8+
private Vector3 velocity;
99
public InputActionReference jumpAction;
1010

1111
public float gravity = 19.62f;
1212
public float jumpForce = 8f;
1313

14+
// Add a NetworkVariable for position
15+
private NetworkVariable<Vector3> netPosition = new NetworkVariable<Vector3>();
16+
1417
private void Awake()
1518
{
1619
character = GetComponent<CharacterController>();
1720
}
1821

1922
private void OnEnable()
2023
{
21-
direction = Vector3.zero;
24+
velocity = Vector3.zero;
2225
jumpAction.action.Enable();
2326
}
2427

@@ -27,46 +30,47 @@ private void OnDisable()
2730
jumpAction.action.Disable();
2831
}
2932

30-
private void Update()
33+
public override void OnNetworkSpawn()
3134
{
32-
if (!IsServer)
35+
if (IsServer)
3336
{
34-
return;
37+
netPosition.Value = transform.position;
3538
}
36-
MovementServerRpc();
3739
}
3840

39-
[ServerRpc]
40-
private void MovementServerRpc()
41+
private void Update()
4142
{
42-
direction += Vector3.down * gravity * Time.deltaTime;
43-
44-
if (character.isGrounded && jumpAction.action.triggered)
43+
if (IsServer)
4544
{
46-
direction = Vector3.up * jumpForce;
45+
HandleMovement();
46+
}
47+
else
48+
{
49+
// Clients update their position based on the NetworkVariable
50+
transform.position = netPosition.Value;
4751
}
48-
49-
character.Move(direction * Time.deltaTime);
50-
51-
UpdateClientRpc(direction);
5252
}
5353

54-
[ClientRpc]
55-
private void UpdateClientRpc(Vector3 serverDirection)
54+
private void HandleMovement()
5655
{
57-
// Update position on clients
58-
if (!IsServer)
56+
velocity += Vector3.down * gravity * Time.deltaTime;
57+
58+
if (character.isGrounded && jumpAction.action.triggered)
5959
{
60-
character.Move(serverDirection * Time.deltaTime);
60+
velocity = Vector3.up * jumpForce;
6161
}
62+
63+
character.Move(velocity * Time.deltaTime);
64+
65+
// Update the NetworkVariable with the new position
66+
netPosition.Value = transform.position;
6267
}
6368

6469
private void OnTriggerEnter(Collider other)
6570
{
66-
6771
if (other.CompareTag("ObstacleCollision"))
6872
{
6973
GameManager.Instance.GameOver(2);
7074
}
7175
}
72-
}
76+
}

Assets/Scripts/EMG.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private async Task ProcessDataEveryInterval(CancellationToken cancellationToken)
7979
{
8080
while (!cancellationToken.IsCancellationRequested)
8181
{
82-
await Task.Delay(300, cancellationToken);
82+
await Task.Delay(100, cancellationToken);
8383
if (newEmgDataReceived)
8484
{
8585
ProcessCurrentEmgData();

0 commit comments

Comments
 (0)