Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions Basic/2DSpaceShooter/Assets/Prefabs/Ship.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ GameObject:
- component: {fileID: 400000}
- component: {fileID: 5000000}
- component: {fileID: 5800000}
- component: {fileID: 509584576524893815}
- component: {fileID: 11400004}
- component: {fileID: 8200000}
- component: {fileID: 8200002}
- component: {fileID: 509584576524893815}
- component: {fileID: -360930162699739946}
- component: {fileID: -8406883944196582507}
- component: {fileID: 7896695181562740567}
Expand All @@ -33,6 +33,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 16.686096, y: -1.5172029, z: 0}
m_LocalScale: {x: 0.6, y: 0.6, z: 0.6}
Expand All @@ -41,7 +42,6 @@ Transform:
- {fileID: 400004}
- {fileID: 1255143139002862940}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!50 &5000000
Rigidbody2D:
Expand Down Expand Up @@ -105,6 +105,26 @@ CircleCollider2D:
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Radius: 0.64
--- !u!114 &509584576524893815
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 4192032552
AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1
ActiveSceneSynchronization: 0
SceneMigrationSynchronization: 1
SpawnWithObservers: 1
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
--- !u!114 &11400004
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -173,7 +193,7 @@ MonoBehaviour:
byte0028: 0
byte0029: 0
m_Friction: {fileID: 19800002}
m_Thrust: {fileID: 19800000}
m_ThrustParticleSystem: {fileID: 19800000}
m_ShipGlow: {fileID: 5983711199006031825}
m_ShipGlowDefaultColor: {r: 1, g: 1, b: 1, a: 1}
m_UIDocument: {fileID: 7896695181562740567}
Expand Down Expand Up @@ -370,25 +390,6 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!114 &509584576524893815
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 951099334
AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1
ActiveSceneSynchronization: 0
SceneMigrationSynchronization: 1
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
--- !u!114 &-360930162699739946
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -485,13 +486,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100002}
serializedVersion: 2
m_LocalRotation: {x: 0.70710284, y: 0.0023588336, z: -0.70710295, w: 0.0023588329}
m_LocalPosition: {x: -1.73, y: 0.05, z: 0.46}
m_LocalScale: {x: 1.26, y: 1.26, z: 1.26}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1255143139002862940}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!198 &19800000
ParticleSystem:
Expand Down Expand Up @@ -5287,13 +5288,15 @@ ParticleSystemRenderer:
m_RenderAlignment: 0
m_Pivot: {x: 0, y: 0, z: 0}
m_Flip: {x: 0, y: 0, z: 0}
m_UseCustomVertexStreams: 0
m_EnableGPUInstancing: 0
m_ApplyActiveColorSpace: 0
m_AllowRoll: 1
m_FreeformStretching: 0
m_RotateWithStretchDirection: 1
m_UseCustomVertexStreams: 0
m_VertexStreams: 0001030405
m_UseCustomTrailVertexStreams: 0
m_TrailVertexStreams: 00010304
m_Mesh: {fileID: 0}
m_Mesh1: {fileID: 0}
m_Mesh2: {fileID: 0}
Expand Down Expand Up @@ -5328,13 +5331,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100004}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 1, z: 0, w: -0}
m_LocalPosition: {x: 0.45, y: -0.019937, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 400000}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!198 &19800002
ParticleSystem:
Expand Down Expand Up @@ -10130,13 +10133,15 @@ ParticleSystemRenderer:
m_RenderAlignment: 0
m_Pivot: {x: 0, y: 0, z: 0}
m_Flip: {x: 0, y: 0, z: 0}
m_UseCustomVertexStreams: 0
m_EnableGPUInstancing: 0
m_ApplyActiveColorSpace: 0
m_AllowRoll: 1
m_FreeformStretching: 0
m_RotateWithStretchDirection: 1
m_UseCustomVertexStreams: 0
m_VertexStreams: 0001030405
m_UseCustomTrailVertexStreams: 0
m_TrailVertexStreams: 00010304
m_Mesh: {fileID: 0}
m_Mesh1: {fileID: 0}
m_Mesh2: {fileID: 0}
Expand Down Expand Up @@ -10170,6 +10175,7 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4711364113217113794}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.27, y: 0, z: 0}
m_LocalScale: {x: 0.3890193, y: 0.3890193, z: 0.3890193}
Expand All @@ -10178,7 +10184,6 @@ Transform:
- {fileID: 389295837323142884}
- {fileID: 400002}
m_Father: {fileID: 400000}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &3390849995755675818
SpriteRenderer:
Expand Down Expand Up @@ -10256,13 +10261,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6021497113750022543}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0, y: 0, z: 0.07}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1255143139002862940}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &5983711199006031825
SpriteRenderer:
Expand Down
15 changes: 7 additions & 8 deletions Basic/2DSpaceShooter/Assets/Scripts/ShipControl.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Unity.Collections;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Assertions;
Expand Down Expand Up @@ -74,7 +73,7 @@ public class ShipControl : NetworkBehaviour
ParticleSystem m_Friction;

[SerializeField]
ParticleSystem m_Thrust;
ParticleSystem m_ThrustParticleSystem;

[SerializeField]
SpriteRenderer m_ShipGlow;
Expand Down Expand Up @@ -107,7 +106,7 @@ public class ShipControl : NetworkBehaviour
float m_OldSpin = 0;

// server movement
private NetworkVariable<float> m_Thrusting = new NetworkVariable<float>();
float m_Thrust;

float m_Spin;

Expand All @@ -119,7 +118,7 @@ void Awake()
m_ObjectPool = GameObject.FindWithTag(s_ObjectPoolTag).GetComponent<NetworkObjectPool>();
Assert.IsNotNull(m_ObjectPool, $"{nameof(NetworkObjectPool)} not found in scene. Did you apply the {s_ObjectPoolTag} to the GameObject?");

m_ThrustMain = m_Thrust.main;
m_ThrustMain = m_ThrustParticleSystem.main;
m_ShipGlow.color = m_ShipGlowDefaultColor;
m_IsBuffed = false;

Expand Down Expand Up @@ -271,15 +270,15 @@ void UpdateServer()
m_Rigidbody2D.angularVelocity = rotate;

// update thrust
if (m_Thrusting.Value != 0)
if (m_Thrust != 0)
{
float accel = m_Acceleration;
if (SpeedBuffTimer.Value > NetworkManager.ServerTime.TimeAsFloat)
{
accel *= 2;
}

Vector3 thrustVec = transform.right * (m_Thrusting.Value * accel);
Vector3 thrustVec = transform.right * (m_Thrust * accel);
m_Rigidbody2D.AddForce(thrustVec);

// restrict max speed
Expand Down Expand Up @@ -504,7 +503,7 @@ void OnCollisionEnter2D(Collision2D other)
[ServerRpc]
public void ThrustServerRpc(float thrusting, int spin)
{
m_Thrusting.Value = thrusting;
m_Thrust = thrusting;
m_Spin = spin;
}

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

### Fixed
- Corrected the variables used for initialization of Health and Energy (#150)
- Converted unnecessary ship thrust NetworkVariable to a float (#149)

### Client Driven

Expand Down