├── ProjectSettings
├── ProjectVersion.txt
├── TagManager.asset
├── AudioManager.asset
├── InputManager.asset
├── NavMeshAreas.asset
├── TimeManager.asset
├── DynamicsManager.asset
├── EditorSettings.asset
├── NetworkManager.asset
├── ProjectSettings.asset
├── QualitySettings.asset
├── GraphicsSettings.asset
├── Physics2DSettings.asset
├── ClusterInputManager.asset
├── EditorBuildSettings.asset
└── UnityConnectSettings.asset
├── Package
└── ArcadeSpaceFlightExample.unitypackage
├── Assets
├── ArcadeSpaceFlight
│ ├── Content
│ │ ├── UI
│ │ │ ├── Crosshair.png
│ │ │ ├── MouseCrosshair.png
│ │ │ ├── Crosshair.png.meta
│ │ │ └── MouseCrosshair.png.meta
│ │ ├── Scenes
│ │ │ ├── Flight.unity
│ │ │ └── Flight.unity.meta
│ │ ├── Prefabs
│ │ │ ├── PlayerShip.prefab
│ │ │ └── PlayerShip.prefab.meta
│ │ ├── UI.meta
│ │ ├── Prefabs.meta
│ │ └── Scenes.meta
│ ├── Code.meta
│ ├── Code
│ │ ├── Ship.meta
│ │ ├── UI.meta
│ │ ├── Camera.meta
│ │ ├── Ship
│ │ │ ├── Ship.cs.meta
│ │ │ ├── ShipInput.cs.meta
│ │ │ ├── ShipPhysics.cs.meta
│ │ │ ├── Ship.cs
│ │ │ ├── ShipPhysics.cs
│ │ │ └── ShipInput.cs
│ │ ├── UI
│ │ │ ├── SpeedUI.cs.meta
│ │ │ ├── MouseCrosshairUI.cs.meta
│ │ │ ├── SpeedUI.cs
│ │ │ └── MouseCrosshairUI.cs
│ │ └── Camera
│ │ │ ├── LagCamera.cs.meta
│ │ │ └── LagCamera.cs
│ └── Content.meta
├── RandomAreaSpawner
│ ├── Prefabs
│ │ ├── AsteroidCube.prefab
│ │ ├── AsteroidSpawner.prefab
│ │ ├── AsteroidCube.prefab.meta
│ │ └── AsteroidSpawner.prefab.meta
│ ├── Prefabs.meta
│ ├── RandomAreaSpawner.cs.meta
│ └── RandomAreaSpawner.cs
├── ArcadeSpaceFlight.meta
└── RandomAreaSpawner.meta
├── .gitignore
├── LICENSE.md
└── README.md
/ProjectSettings/ProjectVersion.txt:
--------------------------------------------------------------------------------
1 | m_EditorVersion: 5.6.2f1
2 |
--------------------------------------------------------------------------------
/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/TagManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/AudioManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/InputManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/InputManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/NavMeshAreas.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/NavMeshAreas.asset
--------------------------------------------------------------------------------
/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/TimeManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/DynamicsManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/EditorSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/NetworkManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/ProjectSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/ProjectSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/QualitySettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/GraphicsSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/Physics2DSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/ClusterInputManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/ClusterInputManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/EditorBuildSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/UnityConnectSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/ProjectSettings/UnityConnectSettings.asset
--------------------------------------------------------------------------------
/Package/ArcadeSpaceFlightExample.unitypackage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/Package/ArcadeSpaceFlightExample.unitypackage
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content/UI/Crosshair.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/Assets/ArcadeSpaceFlight/Content/UI/Crosshair.png
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content/Scenes/Flight.unity:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/Assets/ArcadeSpaceFlight/Content/Scenes/Flight.unity
--------------------------------------------------------------------------------
/Assets/RandomAreaSpawner/Prefabs/AsteroidCube.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/Assets/RandomAreaSpawner/Prefabs/AsteroidCube.prefab
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content/UI/MouseCrosshair.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/Assets/ArcadeSpaceFlight/Content/UI/MouseCrosshair.png
--------------------------------------------------------------------------------
/Assets/RandomAreaSpawner/Prefabs/AsteroidSpawner.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/Assets/RandomAreaSpawner/Prefabs/AsteroidSpawner.prefab
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content/Prefabs/PlayerShip.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brihernandez/ArcadeSpaceFlightExample/HEAD/Assets/ArcadeSpaceFlight/Content/Prefabs/PlayerShip.prefab
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 498cccebf220de94a99418a09c78e7ba
3 | folderAsset: yes
4 | timeCreated: 1503449997
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content/Scenes/Flight.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2aaba6316bc440345a6869dfbbebc18a
3 | timeCreated: 1503449997
4 | licenseType: Free
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/RandomAreaSpawner.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e4bc2627036cdcf4a8c60c79145c5b63
3 | folderAsset: yes
4 | timeCreated: 1487035554
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 88dc402497ac4a84b93deefc351d8324
3 | folderAsset: yes
4 | timeCreated: 1503452109
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/Ship.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: dbdefa8023da9d9478ef1fcd4ca929d1
3 | folderAsset: yes
4 | timeCreated: 1503452201
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/UI.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0166a5f5ae5e48141a08d1d8bbbc4491
3 | folderAsset: yes
4 | timeCreated: 1503455772
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 628524b06033af04b94bc41677a357ff
3 | folderAsset: yes
4 | timeCreated: 1503449997
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content/UI.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6672baa8f52c67f4c9de76cde42da932
3 | folderAsset: yes
4 | timeCreated: 1503454723
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/RandomAreaSpawner/Prefabs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 878a850aab424ff45b4cefddbfe54fa7
3 | folderAsset: yes
4 | timeCreated: 1487038354
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/Camera.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cfe4ec48d86030a46a380a679d250027
3 | folderAsset: yes
4 | timeCreated: 1503457556
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content/Prefabs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f59704db8dae58f48bdf73ef5ff122c7
3 | folderAsset: yes
4 | timeCreated: 1503455442
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content/Scenes.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 25f9c435353a8b448a15b80cd14760fe
3 | folderAsset: yes
4 | timeCreated: 1503449997
5 | licenseType: Free
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/RandomAreaSpawner/Prefabs/AsteroidCube.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8ad4830179cb48940bcf1ea63269c2f5
3 | timeCreated: 1487038308
4 | licenseType: Free
5 | NativeFormatImporter:
6 | mainObjectFileID: 100100000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/RandomAreaSpawner/Prefabs/AsteroidSpawner.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 10c7301dfe1e94d41ad2059639e36c74
3 | timeCreated: 1487038387
4 | licenseType: Free
5 | NativeFormatImporter:
6 | mainObjectFileID: 100100000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content/Prefabs/PlayerShip.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 118efdd877e08f94db8b8ba4780bf098
3 | timeCreated: 1503455444
4 | licenseType: Free
5 | NativeFormatImporter:
6 | mainObjectFileID: 100100000
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/Ship/Ship.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 76b58cb9e30ec724fb88a15da2da0354
3 | timeCreated: 1503453285
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/UI/SpeedUI.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6e5951e5f3d7f7848b82ecdafd0e2b90
3 | timeCreated: 1503459496
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/Camera/LagCamera.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 82bcb5988f343ae49b901c514316383c
3 | timeCreated: 1503457556
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/Ship/ShipInput.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c0f3cffa8d3c0ec449aa2ab4930c283f
3 | timeCreated: 1503452210
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/Ship/ShipPhysics.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c50f670a7dea945489b01d6adedb472f
3 | timeCreated: 1503453926
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/RandomAreaSpawner/RandomAreaSpawner.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b26935f1a42396344ab754e3d8171197
3 | timeCreated: 1471392802
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/UI/MouseCrosshairUI.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 30d9ead275df2b643afde4c1bf9f48bb
3 | timeCreated: 1503455785
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /[Ll]ibrary/
2 | /[Tt]emp/
3 | /[Oo]bj/
4 | /[Bb]uild/
5 | /[Bb]uilds/
6 | /Assets/AssetStoreTools*
7 |
8 | # Visual Studio 2015 cache directory
9 | /.vs/
10 |
11 | # Autogenerated VS/MD/Consulo solution and project files
12 | ExportedObj/
13 | .consulo/
14 | *.csproj
15 | *.unityproj
16 | *.sln
17 | *.suo
18 | *.tmp
19 | *.user
20 | *.userprefs
21 | *.pidb
22 | *.booproj
23 | *.svd
24 | *.pdb
25 |
26 | # Unity3D generated meta files
27 | *.pidb.meta
28 |
29 | # Unity3D Generated File On Crash Reports
30 | sysinfo.txt
31 |
32 | # Builds
33 | *.apk
34 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/UI/SpeedUI.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Brian Hernandez. All rights reserved.
3 | // Licensed under the MIT license. See LICENSE file in the project root for details.
4 | //
5 |
6 | using UnityEngine;
7 | using UnityEngine.UI;
8 |
9 | ///
10 | /// Shows throttle and speed of the player ship.
11 | ///
12 | public class SpeedUI : MonoBehaviour
13 | {
14 | private Text text;
15 |
16 | private void Awake()
17 | {
18 | text = GetComponent();
19 | }
20 |
21 | // Update is called once per frame
22 | void Update()
23 | {
24 | if (text != null && Ship.PlayerShip != null)
25 | {
26 | text.text = string.Format("THR: {0}\nSPD: {1}", (Ship.PlayerShip.Throttle * 100.0f).ToString("000"), Ship.PlayerShip.Velocity.magnitude.ToString("000"));
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2017 Brian Hernandez
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/UI/MouseCrosshairUI.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Brian Hernandez. All rights reserved.
3 | // Licensed under the MIT license. See LICENSE file in the project root for details.
4 | //
5 |
6 | using UnityEngine;
7 | using UnityEngine.UI;
8 |
9 | ///
10 | /// Updates the position of this GameObject to reflect the position of the mouse
11 | /// when the player ship is using mouse input. Otherwise, it just hides it.
12 | ///
13 | public class MouseCrosshairUI : MonoBehaviour
14 | {
15 | private Image crosshair;
16 |
17 | private void Awake()
18 | {
19 | crosshair = GetComponent();
20 | }
21 |
22 | private void Update()
23 | {
24 | if (crosshair != null && Ship.PlayerShip != null)
25 | {
26 | crosshair.enabled = Ship.PlayerShip.UsingMouseInput;
27 |
28 | if (crosshair.enabled)
29 | {
30 | crosshair.transform.position = Input.mousePosition;
31 | Cursor.visible = false;
32 | Cursor.lockState = CursorLockMode.Confined;
33 | }
34 | else
35 | {
36 | Cursor.visible = true;
37 | Cursor.lockState = CursorLockMode.None;
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/Ship/Ship.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Brian Hernandez. All rights reserved.
3 | // Licensed under the MIT license. See LICENSE file in the project root for details.
4 | //
5 |
6 | using UnityEngine;
7 |
8 | ///
9 | /// Ties all the primary ship components together.
10 | ///
11 | [RequireComponent(typeof(Rigidbody))]
12 | [RequireComponent(typeof(ShipPhysics))]
13 | [RequireComponent(typeof(ShipInput))]
14 | public class Ship : MonoBehaviour
15 | {
16 | public bool isPlayer = false;
17 |
18 | private ShipInput input;
19 | private ShipPhysics physics;
20 |
21 | // Keep a static reference for whether or not this is the player ship. It can be used
22 | // by various gameplay mechanics. Returns the player ship if possible, otherwise null.
23 | public static Ship PlayerShip { get { return playerShip; } }
24 | private static Ship playerShip;
25 |
26 | // Getters for external objects to reference things like input.
27 | public bool UsingMouseInput { get { return input.useMouseInput; } }
28 | public Vector3 Velocity { get { return physics.Rigidbody.velocity; } }
29 | public float Throttle { get { return input.throttle; } }
30 |
31 | private void Awake()
32 | {
33 | input = GetComponent();
34 | physics = GetComponent();
35 | }
36 |
37 | private void Update()
38 | {
39 | // Pass the input to the physics to move the ship.
40 | physics.SetPhysicsInput(new Vector3(input.strafe, 0.0f, input.throttle), new Vector3(input.pitch, input.yaw, input.roll));
41 |
42 | // If this is the player ship, then set the static reference. If more than one ship
43 | // is set to player, then whatever happens to be the last ship to be updated will be
44 | // considered the player. Don't let this happen.
45 | if (isPlayer)
46 | playerShip = this;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content/UI/Crosshair.png.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 921be87207a049f41b7a921881c5a712
3 | timeCreated: 1503454733
4 | licenseType: Free
5 | TextureImporter:
6 | fileIDToRecycleName: {}
7 | serializedVersion: 4
8 | mipmaps:
9 | mipMapMode: 0
10 | enableMipMap: 0
11 | sRGBTexture: 1
12 | linearTexture: 0
13 | fadeOut: 0
14 | borderMipMap: 0
15 | mipMapFadeDistanceStart: 1
16 | mipMapFadeDistanceEnd: 3
17 | bumpmap:
18 | convertToNormalMap: 0
19 | externalNormalMap: 0
20 | heightScale: 0.25
21 | normalMapFilter: 0
22 | isReadable: 0
23 | grayScaleToAlpha: 0
24 | generateCubemap: 6
25 | cubemapConvolution: 0
26 | seamlessCubemap: 0
27 | textureFormat: 1
28 | maxTextureSize: 2048
29 | textureSettings:
30 | filterMode: -1
31 | aniso: -1
32 | mipBias: -1
33 | wrapMode: 1
34 | nPOTScale: 0
35 | lightmap: 0
36 | compressionQuality: 50
37 | spriteMode: 1
38 | spriteExtrude: 1
39 | spriteMeshType: 1
40 | alignment: 0
41 | spritePivot: {x: 0.5, y: 0.5}
42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0}
43 | spritePixelsToUnits: 100
44 | alphaUsage: 1
45 | alphaIsTransparency: 1
46 | spriteTessellationDetail: -1
47 | textureType: 8
48 | textureShape: 1
49 | maxTextureSizeSet: 0
50 | compressionQualitySet: 0
51 | textureFormatSet: 0
52 | platformSettings:
53 | - buildTarget: DefaultTexturePlatform
54 | maxTextureSize: 2048
55 | textureFormat: -1
56 | textureCompression: 1
57 | compressionQuality: 50
58 | crunchedCompression: 0
59 | allowsAlphaSplitting: 0
60 | overridden: 0
61 | - buildTarget: Standalone
62 | maxTextureSize: 2048
63 | textureFormat: -1
64 | textureCompression: 1
65 | compressionQuality: 50
66 | crunchedCompression: 0
67 | allowsAlphaSplitting: 0
68 | overridden: 0
69 | spriteSheet:
70 | serializedVersion: 2
71 | sprites: []
72 | outline: []
73 | spritePackingTag:
74 | userData:
75 | assetBundleName:
76 | assetBundleVariant:
77 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Content/UI/MouseCrosshair.png.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d782fbeb8af831440a3b3bc3c6116108
3 | timeCreated: 1503455014
4 | licenseType: Free
5 | TextureImporter:
6 | fileIDToRecycleName: {}
7 | serializedVersion: 4
8 | mipmaps:
9 | mipMapMode: 0
10 | enableMipMap: 0
11 | sRGBTexture: 1
12 | linearTexture: 0
13 | fadeOut: 0
14 | borderMipMap: 0
15 | mipMapFadeDistanceStart: 1
16 | mipMapFadeDistanceEnd: 3
17 | bumpmap:
18 | convertToNormalMap: 0
19 | externalNormalMap: 0
20 | heightScale: 0.25
21 | normalMapFilter: 0
22 | isReadable: 0
23 | grayScaleToAlpha: 0
24 | generateCubemap: 6
25 | cubemapConvolution: 0
26 | seamlessCubemap: 0
27 | textureFormat: 1
28 | maxTextureSize: 2048
29 | textureSettings:
30 | filterMode: -1
31 | aniso: -1
32 | mipBias: -1
33 | wrapMode: 1
34 | nPOTScale: 0
35 | lightmap: 0
36 | compressionQuality: 50
37 | spriteMode: 1
38 | spriteExtrude: 1
39 | spriteMeshType: 1
40 | alignment: 0
41 | spritePivot: {x: 0.5, y: 0.5}
42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0}
43 | spritePixelsToUnits: 100
44 | alphaUsage: 1
45 | alphaIsTransparency: 1
46 | spriteTessellationDetail: -1
47 | textureType: 8
48 | textureShape: 1
49 | maxTextureSizeSet: 0
50 | compressionQualitySet: 0
51 | textureFormatSet: 0
52 | platformSettings:
53 | - buildTarget: DefaultTexturePlatform
54 | maxTextureSize: 2048
55 | textureFormat: -1
56 | textureCompression: 1
57 | compressionQuality: 50
58 | crunchedCompression: 0
59 | allowsAlphaSplitting: 0
60 | overridden: 0
61 | - buildTarget: Standalone
62 | maxTextureSize: 2048
63 | textureFormat: -1
64 | textureCompression: 1
65 | compressionQuality: 50
66 | crunchedCompression: 0
67 | allowsAlphaSplitting: 0
68 | overridden: 0
69 | spriteSheet:
70 | serializedVersion: 2
71 | sprites: []
72 | outline: []
73 | spritePackingTag:
74 | userData:
75 | assetBundleName:
76 | assetBundleVariant:
77 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/Camera/LagCamera.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Brian Hernandez. All rights reserved.
3 | // Licensed under the MIT license. See LICENSE file in the project root for details.
4 | //
5 |
6 | using UnityEngine;
7 |
8 | ///
9 | /// Adds a slight lag to camera rotation to make the third person camera a little more interesting.
10 | /// Requires that it starts parented to something in order to follow it correctly.
11 | ///
12 | [RequireComponent(typeof(Camera))]
13 | public class LagCamera : MonoBehaviour
14 | {
15 | [Tooltip("Speed at which the camera rotates. (Camera uses Slerp for rotation.)")]
16 | public float rotateSpeed = 90.0f;
17 |
18 | [Tooltip("If the parented object is using FixedUpdate for movement, check this box for smoother movement.")]
19 | public bool usedFixedUpdate = true;
20 |
21 | private Transform target;
22 | private Vector3 startOffset;
23 |
24 | private void Start()
25 | {
26 | target = transform.parent;
27 |
28 | if (target == null)
29 | Debug.LogWarning(name + ": Lag Camera will not function correctly without a target.");
30 | if (transform.parent == null)
31 | Debug.LogWarning(name + ": Lag Camera will not function correctly without a parent to derive the initial offset from.");
32 |
33 | startOffset = transform.localPosition;
34 | transform.SetParent(null);
35 | }
36 |
37 | private void Update()
38 | {
39 | if (!usedFixedUpdate)
40 | UpdateCamera();
41 | }
42 |
43 | private void FixedUpdate()
44 | {
45 | if (usedFixedUpdate)
46 | UpdateCamera();
47 | }
48 |
49 | private void UpdateCamera()
50 | {
51 | if (target != null)
52 | {
53 | transform.position = target.TransformPoint(startOffset);
54 | transform.rotation = Quaternion.Slerp(transform.rotation, target.rotation, rotateSpeed * Time.deltaTime);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/Ship/ShipPhysics.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Brian Hernandez. All rights reserved.
3 | // Licensed under the MIT license. See LICENSE file in the project root for details.
4 | //
5 |
6 | using UnityEngine;
7 |
8 | ///
9 | /// Applies linear and angular forces to a ship.
10 | /// This is based on the ship physics from https://github.com/brihernandez/UnityCommon/blob/master/Assets/ShipPhysics/ShipPhysics.cs
11 | ///
12 | public class ShipPhysics : MonoBehaviour
13 | {
14 | [Tooltip("X: Lateral thrust\nY: Vertical thrust\nZ: Longitudinal Thrust")]
15 | public Vector3 linearForce = new Vector3(100.0f, 100.0f, 100.0f);
16 |
17 | [Tooltip("X: Pitch\nY: Yaw\nZ: Roll")]
18 | public Vector3 angularForce = new Vector3(100.0f, 100.0f, 100.0f);
19 |
20 | [Range(0.0f, 1.0f)]
21 | [Tooltip("Multiplier for longitudinal thrust when reverse thrust is requested.")]
22 | public float reverseMultiplier = 1.0f;
23 |
24 | [Tooltip("Multiplier for all forces. Can be used to keep force numbers smaller and more readable.")]
25 | public float forceMultiplier = 100.0f;
26 |
27 | public Rigidbody Rigidbody { get { return rbody; } }
28 |
29 | private Vector3 appliedLinearForce = Vector3.zero;
30 | private Vector3 appliedAngularForce = Vector3.zero;
31 |
32 | private Rigidbody rbody;
33 |
34 | // Keep a reference to the ship this is attached to just in case.
35 | private Ship ship;
36 |
37 | // Use this for initialization
38 | void Awake()
39 | {
40 | rbody = GetComponent();
41 | if (rbody == null)
42 | {
43 | Debug.LogWarning(name + ": ShipPhysics has no rigidbody.");
44 | }
45 |
46 | ship = GetComponent();
47 | }
48 |
49 | void FixedUpdate()
50 | {
51 | if (rbody != null)
52 | {
53 | rbody.AddRelativeForce(appliedLinearForce * forceMultiplier, ForceMode.Force);
54 | rbody.AddRelativeTorque(appliedAngularForce * forceMultiplier, ForceMode.Force);
55 | }
56 | }
57 |
58 | ///
59 | /// Sets the input for how much of linearForce and angularForce are applied
60 | /// to the ship. Each component of the input vectors is assumed to be scaled
61 | /// from -1 to 1, but is not clamped.
62 | ///
63 | public void SetPhysicsInput(Vector3 linearInput, Vector3 angularInput)
64 | {
65 | appliedLinearForce = MultiplyByComponent(linearInput, linearForce);
66 | appliedAngularForce = MultiplyByComponent(angularInput, angularForce);
67 | }
68 |
69 | ///
70 | /// Returns a Vector3 where each component of Vector A is multiplied by the equivalent component of Vector B.
71 | ///
72 | private Vector3 MultiplyByComponent(Vector3 a, Vector3 b)
73 | {
74 | Vector3 ret;
75 |
76 | ret.x = a.x * b.x;
77 | ret.y = a.y * b.y;
78 | ret.z = a.z * b.z;
79 |
80 | return ret;
81 | }
82 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Arcade Space Flight Physics Example
2 | Simple example of arcade style space sim flight physics. Built with Unity 5.6.
3 |
4 | 
5 |
6 | ## Download
7 |
8 | You can either clone the repository, or [download either the demo or asset package from the releases page](https://github.com/brihernandez/ArcadeSpaceFlightExample/releases).
9 |
10 | ## Controls
11 |
12 | There are two control modes supported. The first is **mouse flight** and the second is **traditional**. They can be toggled by checking the "Use Mouse Input" property on the ShipInput component.
13 |
14 | ### Mouse Controls
15 | - W/S: Increase/Decrease throttle
16 | - A/D: Strafe Left/Right
17 | - Mouse scrollwheel: Increase/Decrease throttle
18 | - Mouse motion: Pitch/Yaw
19 |
20 | ### Traditional Controls
21 | - W/S: Pitch Down/Up
22 | - A/D: Yaw Left/Right
23 | - R/T: Increase/Decrease throttle
24 |
25 | Note that with the traditional control setting, a gamepad or joystick's X/Y axes can be used for flight as well.
26 |
27 | ## Component Organization
28 |
29 | When possible, I like to break things off into very self-contained components. This isn't always possible, but I feel it's a good practice in general that keeps your source files small and easily understood. However, this does add some complexity in that it requires you to link components together in some way.
30 |
31 | Personally, I prefer doing these associations in code, especially when the components are likely to be on the same GameObject. In the case of the ship, it's made of three different components: Ship, Input, and Physics. The way I configured it here, the Ship component is meant to represent the entire ship. All external access to ship properties such as velocity or input are meant to go through the ship. In an effort to keep individual components as dumb as possible, and to minimize cross-component dependency, they communicate (only if necessary) to the ship, rather than other components directly. While there isn't an example of this in the project, each component has a reference to the ship just in case. The ship itself also passes information between components as needed.
32 |
33 | There are advantages and disadvantages to this method, but I think it's worth showing as an example of one way to tackle complex component interaction.
34 |
35 | ## Ship
36 |
37 | As mentioned above, the ship component represents the ship as a whole and provides a communication mechanism between components.
38 |
39 | ## Ship Input
40 |
41 | In keeping with the mentality of separating out responsibilities, this component handles all input. In this example, only player input is considered, but it would be trivial to add a flag here to ignore player input if this isn't the player (by checking ship.isPlayer). A great use case for this would be if you want an AI to instead drive the input. Having an input layer between the player/AI, and the ship itself, allows the ship to only care about ship input and not where it's coming from.
42 |
43 | ## Ship Physics
44 |
45 | This component is taken almost verbatim from my [UnityCommon repository](https://github.com/brihernandez/UnityCommon). It's a generic space physics component that can apply forces and torques to a rigidbody using inputs that a ship's input would give. You give it the forces that it can apply in each axis, and then how much of those forces to apply.
46 |
47 | ## Changelog
48 |
49 | ### 1.0 08/24/2017
50 | - Initial commit
--------------------------------------------------------------------------------
/Assets/ArcadeSpaceFlight/Code/Ship/ShipInput.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Brian Hernandez. All rights reserved.
3 | // Licensed under the MIT license. See LICENSE file in the project root for details.
4 | //
5 |
6 | using UnityEngine;
7 |
8 | ///
9 | /// Class specifically to deal with input.
10 | ///
11 | public class ShipInput : MonoBehaviour
12 | {
13 | [Tooltip("When true, the mouse and mousewheel are used for ship input and A/D can be used for strafing like in many arcade space sims.\n\nOtherwise, WASD/Arrows/Joystick + R/T are used for flying, representing a more traditional style space sim.")]
14 | public bool useMouseInput = true;
15 | [Tooltip("When using Keyboard/Joystick input, should roll be added to horizontal stick movement. This is a common trick in traditional space sims to help ships roll into turns and gives a more plane-like feeling of flight.")]
16 | public bool addRoll = true;
17 |
18 | [Space]
19 |
20 | [Range(-1, 1)]
21 | public float pitch;
22 | [Range(-1, 1)]
23 | public float yaw;
24 | [Range(-1, 1)]
25 | public float roll;
26 | [Range(-1, 1)]
27 | public float strafe;
28 | [Range(0, 1)]
29 | public float throttle;
30 |
31 | // How quickly the throttle reacts to input.
32 | private const float THROTTLE_SPEED = 0.5f;
33 |
34 | // Keep a reference to the ship this is attached to just in case.
35 | private Ship ship;
36 |
37 | private void Awake()
38 | {
39 | ship = GetComponent();
40 | }
41 |
42 | private void Update()
43 | {
44 | if (useMouseInput)
45 | {
46 | strafe = Input.GetAxis("Horizontal");
47 | SetStickCommandsUsingMouse();
48 | UpdateMouseWheelThrottle();
49 | UpdateKeyboardThrottle(KeyCode.W, KeyCode.S);
50 | }
51 | else
52 | {
53 | pitch = Input.GetAxis("Vertical");
54 | yaw = Input.GetAxis("Horizontal");
55 |
56 | if (addRoll)
57 | roll = -Input.GetAxis("Horizontal") * 0.5f;
58 |
59 | strafe = 0.0f;
60 | UpdateKeyboardThrottle(KeyCode.R, KeyCode.F);
61 | }
62 | }
63 |
64 | ///
65 | /// Freelancer style mouse controls. This uses the mouse to simulate a virtual joystick.
66 | /// When the mouse is in the center of the screen, this is the same as a centered stick.
67 | ///
68 | private void SetStickCommandsUsingMouse()
69 | {
70 | Vector3 mousePos = Input.mousePosition;
71 |
72 | // Figure out most position relative to center of screen.
73 | // (0, 0) is center, (-1, -1) is bottom left, (1, 1) is top right.
74 | pitch = (mousePos.y - (Screen.height * 0.5f)) / (Screen.height* 0.5f);
75 | yaw = (mousePos.x - (Screen.width * 0.5f)) / (Screen.width * 0.5f);
76 |
77 | // Make sure the values don't exceed limits.
78 | pitch = -Mathf.Clamp(pitch, -1.0f, 1.0f);
79 | yaw = Mathf.Clamp(yaw, -1.0f, 1.0f);
80 | }
81 |
82 | ///
83 | /// Uses R and F to raise and lower the throttle.
84 | ///
85 | private void UpdateKeyboardThrottle(KeyCode increaseKey, KeyCode decreaseKey)
86 | {
87 | float target = throttle;
88 |
89 | if (Input.GetKey(increaseKey))
90 | target = 1.0f;
91 | else if (Input.GetKey(decreaseKey))
92 | target = 0.0f;
93 |
94 | throttle = Mathf.MoveTowards(throttle, target, Time.deltaTime * THROTTLE_SPEED);
95 | }
96 |
97 | ///
98 | /// Uses the mouse wheel to control the throttle.
99 | ///
100 | private void UpdateMouseWheelThrottle()
101 | {
102 | throttle += Input.GetAxis("Mouse ScrollWheel");
103 | throttle = Mathf.Clamp(throttle, 0.0f, 1.0f);
104 | }
105 | }
--------------------------------------------------------------------------------
/Assets/RandomAreaSpawner/RandomAreaSpawner.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) Brian Hernandez. All rights reserved.
3 | // Licensed under the MIT license. See LICENSE file in the project root for details.
4 | //
5 |
6 | using UnityEngine;
7 |
8 | public enum RandomSpawnerShape
9 | {
10 | Box,
11 | Sphere,
12 | }
13 |
14 | // Used mostly for testing to provide stuff to fly around and into.
15 | public class RandomAreaSpawner : MonoBehaviour
16 | {
17 | [Header("General settings:")]
18 |
19 | [Tooltip("Prefab to spawn.")]
20 | public Transform prefab;
21 |
22 | [Tooltip("Shape to spawn the prefabs in.")]
23 | public RandomSpawnerShape spawnShape = RandomSpawnerShape.Sphere;
24 |
25 | [Tooltip("Multiplier for the spawn shape in each axis.")]
26 | public Vector3 shapeModifiers = Vector3.one;
27 |
28 | [Tooltip("How many prefab to spawn.")]
29 | public int asteroidCount = 50;
30 |
31 | [Tooltip("Distance from the center of the gameobject that prefabs will spawn")]
32 | public float range = 1000.0f;
33 |
34 | [Tooltip("Should prefab have a random rotation applied to it.")]
35 | public bool randomRotation = true;
36 |
37 | [Tooltip("Random min/max scale to apply.")]
38 | public Vector2 scaleRange = new Vector2(1.0f, 3.0f);
39 |
40 | [Header("Rigidbody settings:")]
41 |
42 | [Tooltip("Apply a velocity from 0 to this value in a random direction.")]
43 | public float velocity = 0.0f;
44 |
45 | [Tooltip("Apply an angular velocity (deg/s) from 0 to this value in a random direction.")]
46 | public float angularVelocity = 0.0f;
47 |
48 | [Tooltip("If true, raise the mass of the object based on its scale.")]
49 | public bool scaleMass = true;
50 |
51 | // Use this for initialization
52 | void Start()
53 | {
54 | if (prefab != null)
55 | {
56 | for (int i = 0; i < asteroidCount; i++)
57 | CreateAsteroid();
58 | }
59 | }
60 |
61 | private void CreateAsteroid()
62 | {
63 | Vector3 spawnPos = Vector3.zero;
64 |
65 | // Create random position based on specified shape and range.
66 | if (spawnShape == RandomSpawnerShape.Box)
67 | {
68 | spawnPos.x = Random.Range(-range, range) * shapeModifiers.x;
69 | spawnPos.y = Random.Range(-range, range) * shapeModifiers.y;
70 | spawnPos.z = Random.Range(-range, range) * shapeModifiers.z;
71 | }
72 | else if (spawnShape == RandomSpawnerShape.Sphere)
73 | {
74 | spawnPos = Random.insideUnitSphere * range;
75 | spawnPos.x *= shapeModifiers.x;
76 | spawnPos.y *= shapeModifiers.y;
77 | spawnPos.z *= shapeModifiers.z;
78 | }
79 |
80 | // Offset position to match position of the parent gameobject.
81 | spawnPos += transform.position;
82 |
83 | // Apply a random rotation if necessary.
84 | Quaternion spawnRot = (randomRotation) ? Random.rotation : Quaternion.identity;
85 |
86 | // Create the object and set the parent to this gameobject for scene organization.
87 | Transform t = Instantiate(prefab, spawnPos, spawnRot) as Transform;
88 | t.SetParent(transform);
89 |
90 | // Apply scaling.
91 | float scale = Random.Range(scaleRange.x, scaleRange.y);
92 | t.localScale = Vector3.one * scale;
93 |
94 | // Apply rigidbody values.
95 | Rigidbody r = t.GetComponent();
96 | if (r)
97 | {
98 | if (scaleMass)
99 | r.mass *= scale * scale * scale;
100 |
101 | r.AddRelativeForce(Random.insideUnitSphere * velocity, ForceMode.VelocityChange);
102 | r.AddRelativeTorque(Random.insideUnitSphere * angularVelocity * Mathf.Deg2Rad, ForceMode.VelocityChange);
103 | }
104 | }
105 |
106 | public void CreateNewAstroid()
107 | {
108 | CreateAsteroid();
109 | }
110 | }
111 |
--------------------------------------------------------------------------------