The fucking 3rd time i had to upload this project to git

This commit is contained in:
Madhav Kapa
2023-10-06 20:18:29 -04:00
commit 5658acfe16
2689 changed files with 1259400 additions and 0 deletions

BIN
Assets/Scripts/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 57cc37cd3cd5ef244a64a8d2a31d84b7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,28 @@
using Player.Information;
using UnityEngine;
public class ConstructArea : ConstructBase
{
[SerializeField] private string resourceName = "";
[SerializeField] private float resourceRate;
[SerializeField] private float radiusEffect;
private GameObject player;
private PlayerStats playerStats;
// Start is called before the first frame update
private void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
playerStats = player.GetComponent<PlayerStats>();
}
// Update is called once per frame
private void Update()
{
if (Vector3.Distance(player.transform.position, transform.position) <= radiusEffect)
playerStats.ConsumeResource(resourceRate * Time.deltaTime, resourceName);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1d286e9c290eb46609cf5c63860d895a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,32 @@
using UnityEngine;
public class ConstructBase : MonoBehaviour
{
[SerializeField] private int naniteCost = 1;
// Start is called before the first frame update
private void Start()
{
}
// Update is called once per frame
private void Update()
{
}
// called whenever the player collects the resources from this construct
public void Interact()
{
}
public int Disassemble()
{
Destroy(gameObject);
return naniteCost;
}
public int GetCost()
{
return naniteCost;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 83f7334cb0b8146daa47bb6225d1c483
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,48 @@
using TMPro;
using UnityEngine;
public class ConstructMaker : ConstructBase
{
[SerializeField] private string resourceName = "";
[SerializeField] private float resourceMax;
[SerializeField] private float resourceRate;
private float resource;
private TMP_Text resourceIndicator;
private void Start()
{
resourceIndicator = transform.Find("ResourceIndicator").GetComponent<TMP_Text>();
}
private void Update()
{
if (resource != resourceMax)
{
resource = Mathf.Clamp(resource + resourceRate * Time.deltaTime, 0f, resourceMax);
resourceIndicator.SetText(resourceName + ":\n" + Mathf.FloorToInt(resource));
}
}
public void SetProperties(string name, float max, float rate)
{
resourceName = name;
resourceMax = max;
resourceRate = rate;
}
public new float Interact()
{
var amount = resource;
resource = 0f;
return amount;
}
public string GetResource()
{
return resourceName;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fe814975be4c040bb9ca783a86651225
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,85 @@
using TMPro;
using UnityEngine;
using Player.Information;
public class ConstructManager : MonoBehaviour
{
[SerializeField] private bool isMaker = true;
[SerializeField] private string resourceName = "";
[SerializeField] private float resourceMax = 50f;
[SerializeField] private float resourceRate = 1f;
[SerializeField] private float radiusEffect = 5f;
private GameObject player;
private PlayerStats playerStats;
private float resource;
private TMP_Text resourceIndicator;
// Start is called before the first frame update
private void Start()
{
resourceIndicator = transform.Find("ResourceIndicator").GetComponent<TMP_Text>();
if (isMaker)
{
resourceIndicator = transform.Find("ResourceIndicator").GetComponent<TMP_Text>();
}
else
{
resourceIndicator.enabled = false;
player = GameObject.FindGameObjectWithTag("Player");
playerStats = player.GetComponent<PlayerStats>();
}
}
// Update is called once per frame
private void Update()
{
if (isMaker)
{
if (resource != resourceMax)
{
resource = Mathf.Clamp(resource + resourceRate * Time.deltaTime, 0f, resourceMax);
resourceIndicator.SetText(resourceName + ":\n" + Mathf.FloorToInt(resource));
}
}
else
{
if (Vector3.Distance(player.transform.position, transform.position) <= radiusEffect)
playerStats.ChangeHealth(resourceRate * Time.deltaTime);
}
}
// called whenever the player collects the resources from this construct
public float CollectAll()
{
if (isMaker)
{
var amount = resource;
resource = 0f;
return amount;
}
return 0f;
}
public void Disassemble()
{
Destroy(gameObject);
}
public bool IsMaker()
{
return isMaker;
}
public string GetResource()
{
return resourceName;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8d47f4cb96974450ac18ad56e19ab56
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,41 @@
using TMPro;
using UnityEngine;
public class FoodMakerController : MonoBehaviour
{
[SerializeField] private float foodMax = 50f;
[SerializeField] private float foodRate = 1f;
private float food;
private TMP_Text foodIndicator;
// Start is called before the first frame update
private void Start()
{
food = 0f;
foodIndicator = transform.Find("FoodIndicator").GetComponent<TMP_Text>();
}
// Update is called once per frame
private void Update()
{
food = Mathf.Clamp(food + foodRate * Time.deltaTime, 0f, foodMax);
foodIndicator.SetText("Food:\n" + Mathf.FloorToInt(food));
}
// called whenever the player collects the resources from this construct
public float CollectAll()
{
var amount = food;
food = 0f;
return amount;
}
public void Disassemble()
{
Destroy(gameObject);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e1508925f2df548bdb47bdce29154c00
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,34 @@
using NoiseTest;
using UnityEngine;
public class EnvironmentBase
{
public OpenSimplexNoise test = new();
// Start is called before the first frame update
private void Start()
{
}
// Update is called once per frame
private void Update()
{
}
public float GetTest(Vector2 pos)
{
var posx = new decimal(pos.x);
var posy = new decimal(pos.y);
return (float)test.Evaluate((double)posx, (double)posy);
}
public float GetNutrients()
{
return 1f;
}
public float GetTemperature()
{
return 1f;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fcfd09aa5a17c4587b76c2beaf720f5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f8465df97975d433a93240ff217bea6e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,28 @@
using System.Linq;
using UnityEngine;
public class DependAppear : MonoBehaviour
{
public GameObject[] dependents;
public GameObject[] targets;
private bool allCollected;
// Start is called before the first frame update
private void Start()
{
foreach (var obj in targets) obj.SetActive(false);
allCollected = false;
}
// Update is called once per frame
private void Update()
{
if (!allCollected)
{
allCollected = dependents.Select(x => !x.activeSelf).Aggregate((x, y) => x && y);
if (allCollected)
foreach (var obj in targets)
obj.SetActive(true);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0bbb0992303414c6e99433ff5c723b15
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,206 @@
using UnityEditor;
using UnityEngine;
public class MovingPlatform : MonoBehaviour
{
public float translationSpeedX = 1.0f; // Speed of translation along X-axis
public float translationSpeedY = 1.0f; // Speed of translation along Y-axis
public float translationSpeedZ = 1.0f; // Speed of translation along Z-axis
public float rotationSpeedX = 1.0f; // Speed of rotation around X-axis
public float rotationSpeedY = 1.0f; // Speed of rotation around Y-axis
public float rotationSpeedZ = 1.0f; // Speed of rotation around Z-axis
public float translationAmplitudeX = 1.0f; // Amplitude of translation along X-axis
public float translationAmplitudeY = 1.0f; // Amplitude of translation along Y-axis
public float translationAmplitudeZ = 1.0f; // Amplitude of translation along Z-axis
public float rotationAmplitudeX = 30.0f; // Amplitude of rotation around X-axis
public float rotationAmplitudeY = 30.0f; // Amplitude of rotation around Y-axis
public float rotationAmplitudeZ = 30.0f; // Amplitude of rotation around Z-axis
public bool translationX; // Enable translation along X-axis
public bool translationY; // Enable translation along Y-axis
public bool translationZ; // Enable translation along Z-axis
public bool rotationX; // Enable rotation around X-axis
public bool rotationY; // Enable rotation around Y-axis
public bool rotationZ; // Enable rotation around Z-axis
public bool constantrotX; // Enable nonsine translation along X-axis
public bool constantrotY; // Enable nonsine translation along Y-axis
public bool constantrotZ; // Enable nonsine translation along Z-axis
private Vector3 _initialPosition; // Initial position of the object
private Quaternion _initialRotation; // Initial rotation of the object
private Transform _transform; // Cached transform
private void Start()
{
_transform = transform;
// Store the initial position and rotation of the object
_initialPosition = _transform.position;
_initialRotation = _transform.rotation;
}
private void Update()
{
// Calculate the new position and rotation using sine curves
// Translation
var translationOffsetX = translationX ? Mathf.Sin(Time.time * translationSpeedX) * translationAmplitudeX : 0.0f;
var translationOffsetY = translationY ? Mathf.Sin(Time.time * translationSpeedY) * translationAmplitudeY : 0.0f;
var translationOffsetZ = translationZ ? Mathf.Sin(Time.time * translationSpeedZ) * translationAmplitudeZ : 0.0f;
// Rotation
float rotationOffsetX;
float rotationOffsetY;
float rotationOffsetZ;
if (constantrotX == false)
rotationOffsetX = rotationX ? Mathf.Sin(Time.time * rotationSpeedX) * rotationAmplitudeX : 0.0f;
else
rotationOffsetX = rotationX ? Time.time * rotationSpeedX * rotationAmplitudeX : 0.0f;
if (constantrotY == false)
rotationOffsetY = rotationY ? Mathf.Sin(Time.time * rotationSpeedY) * rotationAmplitudeY : 0.0f;
else
rotationOffsetY = rotationY ? Time.time * rotationSpeedY * rotationAmplitudeY : 0.0f;
if (constantrotZ == false)
rotationOffsetZ = rotationZ ? Mathf.Sin(Time.time * rotationSpeedZ) * rotationAmplitudeZ : 0.0f;
else
rotationOffsetZ = rotationZ ? Time.time * rotationSpeedZ * rotationAmplitudeZ : 0.0f;
// Calculate the rotation around the center of the object
// Calculate the rotation around the center of the object
Vector3 centerOffset = _transform.InverseTransformPoint(_transform.position); // Get the offset from the center of the object
Quaternion quatrotationX = Quaternion.Euler(rotationOffsetX, 0, 0);
Quaternion quatrotationY = Quaternion.Euler(0, rotationOffsetY, 0);
Quaternion quatrotationZ = Quaternion.Euler(0, 0, rotationOffsetZ);
Quaternion rotation = quatrotationX * quatrotationY * quatrotationZ; // Calculate the rotation
_transform.rotation = rotation * Quaternion.LookRotation(centerOffset); // Apply rotation around the center
// Update the position and rotation of the object
_transform.position = _initialPosition +
new Vector3(translationOffsetX, translationOffsetY, translationOffsetZ); // Update translation
_transform.rotation = _initialRotation * quatrotationX * quatrotationY * quatrotationZ; // Update rotation
}
}
#if UNITY_EDITOR
// Custom editor for MovingPlatform script
[CustomEditor(typeof(MovingPlatform))]
public class MovingPlatformEditor : Editor
{
private bool _showRotationSettings = true;
private bool _showTranslationSettings = true;
public override void OnInspectorGUI()
{
// Draw the default inspector
// Get the MovingPlatform script
var movingPlatform = (MovingPlatform)target;
// Display custom fields for translation and rotation settings
// add foldout for translation settings
_showTranslationSettings = EditorGUILayout.Foldout(_showTranslationSettings, "Translation Settings", true,
EditorStyles.foldoutHeader);
// Display translation X settings
if (_showTranslationSettings)
{
EditorGUI.indentLevel++;
// Display translation X settings
movingPlatform.translationX = EditorGUILayout.Toggle("Translation X", movingPlatform.translationX);
if (movingPlatform.translationX)
{
movingPlatform.translationSpeedX =
EditorGUILayout.FloatField("Translation Speed X", movingPlatform.translationSpeedX);
movingPlatform.translationAmplitudeX =
EditorGUILayout.FloatField("Translation Amplitude X", movingPlatform.translationAmplitudeX);
}
// Display translation Y settings
movingPlatform.translationY = EditorGUILayout.Toggle("Translation Y", movingPlatform.translationY);
if (movingPlatform.translationY)
{
movingPlatform.translationSpeedY =
EditorGUILayout.FloatField("Translation Speed Y", movingPlatform.translationSpeedY);
movingPlatform.translationAmplitudeY =
EditorGUILayout.FloatField("Translation Amplitude Y", movingPlatform.translationAmplitudeY);
}
// Display translation Z settings
movingPlatform.translationZ = EditorGUILayout.Toggle("Translation Z", movingPlatform.translationZ);
if (movingPlatform.translationZ)
{
movingPlatform.translationSpeedZ =
EditorGUILayout.FloatField("Translation Speed Z", movingPlatform.translationSpeedZ);
movingPlatform.translationAmplitudeZ =
EditorGUILayout.FloatField("Translation Amplitude Z", movingPlatform.translationAmplitudeZ);
}
EditorGUI.indentLevel--;
}
// add foldout for rotation settings
_showRotationSettings = EditorGUILayout.Foldout(_showRotationSettings, "Rotation Settings", true,
EditorStyles.foldoutHeader);
if (_showRotationSettings)
{
EditorGUI.indentLevel++;
movingPlatform.rotationX = EditorGUILayout.Toggle("Rotation X", movingPlatform.rotationX);
if (movingPlatform.rotationX)
{
movingPlatform.rotationSpeedX =
EditorGUILayout.FloatField("Rotation Speed X", movingPlatform.rotationSpeedX);
movingPlatform.constantrotX =
EditorGUILayout.Toggle("Constant Rotation X", movingPlatform.constantrotX);
if (!movingPlatform.constantrotX)
movingPlatform.rotationAmplitudeX =
EditorGUILayout.Slider("Rotation Amplitude X", movingPlatform.rotationAmplitudeX, 0.0f, 360.0f);
}
movingPlatform.rotationY = EditorGUILayout.Toggle("Rotation Y", movingPlatform.rotationY);
if (movingPlatform.rotationY)
{
movingPlatform.rotationSpeedY =
EditorGUILayout.FloatField("Rotation Speed Y", movingPlatform.rotationSpeedY);
movingPlatform.constantrotY =
EditorGUILayout.Toggle("Constant Rotation Y", movingPlatform.constantrotY);
if (!movingPlatform.constantrotY)
movingPlatform.rotationAmplitudeY =
EditorGUILayout.Slider("Rotation Amplitude Y", movingPlatform.rotationAmplitudeY, 0.0f, 360.0f);
}
movingPlatform.rotationZ = EditorGUILayout.Toggle("Rotation Z", movingPlatform.rotationZ);
if (movingPlatform.rotationZ)
{
movingPlatform.rotationSpeedZ =
EditorGUILayout.FloatField("Rotation Speed Z", movingPlatform.rotationSpeedZ);
movingPlatform.constantrotZ =
EditorGUILayout.Toggle("Constant Rotation Z", movingPlatform.constantrotZ);
if (!movingPlatform.constantrotZ)
movingPlatform.rotationAmplitudeZ =
EditorGUILayout.Slider("Rotation Amplitude Z", movingPlatform.rotationAmplitudeZ, 0.0f, 360.0f);
}
EditorGUI.indentLevel--;
}
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9e2fb7d8a4ff9ac43b4d860f982dab82
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
using UnityEngine;
public class TraversalProperties : MonoBehaviour
{
[SerializeField] public bool canGrappleOnto;
[SerializeField] public bool lethalToEnter;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b7990ac7d1b27486c887ffb3550956cd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,12 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class TriggerLevelChange : MonoBehaviour
{
public string levelToLoad;
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player") SceneManager.LoadScene(levelToLoad);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a881360b82b9241deba8e1d70e7acf87
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,35 @@
using UnityEngine;
public class MainMenu : MonoBehaviour
{
private GameObject canvas;
// Start is called before the first frame update
private void Start()
{
canvas = GameObject.Find("Canvas");
Cursor.lockState = CursorLockMode.None;
}
// Update is called once per frame
private void Update()
{
}
public void StartGame()
{
canvas.SetActive(false);
Initiate.Fade("Tutorial", Color.black, 2.0f);
}
public void StartChaos()
{
canvas.SetActive(false);
Initiate.Fade("Chaos", Color.black, 2.0f);
}
public void QuitGame()
{
Application.Quit();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91e590c0fb81fcc4db0b258ef5f54b66
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,582 @@
/* OpenSimplex Noise in C#
* Ported from https://gist.github.com/KdotJPG/b1270127455a94ac5d19
* and heavily refactored to improve performance. */
using System;
using System.Runtime.CompilerServices;
namespace NoiseTest
{
public class OpenSimplexNoise
{
private const double STRETCH_2D = -0.211324865405187; //(1/Math.sqrt(2+1)-1)/2;
private const double STRETCH_3D = -1.0 / 6.0; //(1/Math.sqrt(3+1)-1)/3;
private const double STRETCH_4D = -0.138196601125011; //(1/Math.sqrt(4+1)-1)/4;
private const double SQUISH_2D = 0.366025403784439; //(Math.sqrt(2+1)-1)/2;
private const double SQUISH_3D = 1.0 / 3.0; //(Math.sqrt(3+1)-1)/3;
private const double SQUISH_4D = 0.309016994374947; //(Math.sqrt(4+1)-1)/4;
private const double NORM_2D = 1.0 / 47.0;
private const double NORM_3D = 1.0 / 103.0;
private const double NORM_4D = 1.0 / 30.0;
private static readonly double[] gradients2D =
{
5, 2, 2, 5,
-5, 2, -2, 5,
5, -2, 2, -5,
-5, -2, -2, -5
};
private static readonly double[] gradients3D =
{
-11, 4, 4, -4, 11, 4, -4, 4, 11,
11, 4, 4, 4, 11, 4, 4, 4, 11,
-11, -4, 4, -4, -11, 4, -4, -4, 11,
11, -4, 4, 4, -11, 4, 4, -4, 11,
-11, 4, -4, -4, 11, -4, -4, 4, -11,
11, 4, -4, 4, 11, -4, 4, 4, -11,
-11, -4, -4, -4, -11, -4, -4, -4, -11,
11, -4, -4, 4, -11, -4, 4, -4, -11
};
private static readonly double[] gradients4D =
{
3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3,
-3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3,
3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3,
-3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3,
3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3,
-3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3,
3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3,
-3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3,
3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3,
-3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3,
3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3,
-3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3,
3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3,
-3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3,
3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3,
-3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3
};
private static readonly Contribution2[] lookup2D;
private static readonly Contribution3[] lookup3D;
private static readonly Contribution4[] lookup4D;
private readonly byte[] perm;
private readonly byte[] perm2D;
private readonly byte[] perm3D;
private readonly byte[] perm4D;
static OpenSimplexNoise()
{
var base2D = new[]
{
new[] { 1, 1, 0, 1, 0, 1, 0, 0, 0 },
new[] { 1, 1, 0, 1, 0, 1, 2, 1, 1 }
};
var p2D = new[] { 0, 0, 1, -1, 0, 0, -1, 1, 0, 2, 1, 1, 1, 2, 2, 0, 1, 2, 0, 2, 1, 0, 0, 0 };
var lookupPairs2D = new[]
{ 0, 1, 1, 0, 4, 1, 17, 0, 20, 2, 21, 2, 22, 5, 23, 5, 26, 4, 39, 3, 42, 4, 43, 3 };
var contributions2D = new Contribution2[p2D.Length / 4];
for (var i = 0; i < p2D.Length; i += 4)
{
var baseSet = base2D[p2D[i]];
Contribution2 previous = null, current = null;
for (var k = 0; k < baseSet.Length; k += 3)
{
current = new Contribution2(baseSet[k], baseSet[k + 1], baseSet[k + 2]);
if (previous == null)
contributions2D[i / 4] = current;
else
previous.Next = current;
previous = current;
}
current.Next = new Contribution2(p2D[i + 1], p2D[i + 2], p2D[i + 3]);
}
lookup2D = new Contribution2[64];
for (var i = 0; i < lookupPairs2D.Length; i += 2)
lookup2D[lookupPairs2D[i]] = contributions2D[lookupPairs2D[i + 1]];
var base3D = new[]
{
new[] { 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1 },
new[] { 2, 1, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1, 3, 1, 1, 1 },
new[] { 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 2, 1, 1, 0, 2, 1, 0, 1, 2, 0, 1, 1 }
};
var p3D = new[]
{
0, 0, 1, -1, 0, 0, 1, 0, -1, 0, 0, -1, 1, 0, 0, 0, 1, -1, 0, 0, -1, 0, 1, 0, 0, -1, 1, 0, 2, 1, 1, 0, 1,
1, 1, -1, 0, 2, 1, 0, 1, 1, 1, -1, 1, 0, 2, 0, 1, 1, 1, -1, 1, 1, 1, 3, 2, 1, 0, 3, 1, 2, 0, 1, 3, 2, 0,
1, 3, 1, 0, 2, 1, 3, 0, 2, 1, 3, 0, 1, 2, 1, 1, 1, 0, 0, 2, 2, 0, 0, 1, 1, 0, 1, 0, 2, 0, 2, 0, 1, 1, 0,
0, 1, 2, 0, 0, 2, 2, 0, 0, 0, 0, 1, 1, -1, 1, 2, 0, 0, 0, 0, 1, -1, 1, 1, 2, 0, 0, 0, 0, 1, 1, 1, -1, 2,
3, 1, 1, 1, 2, 0, 0, 2, 2, 3, 1, 1, 1, 2, 2, 0, 0, 2, 3, 1, 1, 1, 2, 0, 2, 0, 2, 1, 1, -1, 1, 2, 0, 0,
2, 2, 1, 1, -1, 1, 2, 2, 0, 0, 2, 1, -1, 1, 1, 2, 0, 0, 2, 2, 1, -1, 1, 1, 2, 0, 2, 0, 2, 1, 1, 1, -1,
2, 2, 0, 0, 2, 1, 1, 1, -1, 2, 0, 2, 0
};
var lookupPairs3D = new[]
{
0, 2, 1, 1, 2, 2, 5, 1, 6, 0, 7, 0, 32, 2, 34, 2, 129, 1, 133, 1, 160, 5, 161, 5, 518, 0, 519, 0, 546,
4, 550, 4, 645, 3, 647, 3, 672, 5, 673, 5, 674, 4, 677, 3, 678, 4, 679, 3, 680, 13, 681, 13, 682, 12,
685, 14, 686, 12, 687, 14, 712, 20, 714, 18, 809, 21, 813, 23, 840, 20, 841, 21, 1198, 19, 1199, 22,
1226, 18, 1230, 19, 1325, 23, 1327, 22, 1352, 15, 1353, 17, 1354, 15, 1357, 17, 1358, 16, 1359, 16,
1360, 11, 1361, 10, 1362, 11, 1365, 10, 1366, 9, 1367, 9, 1392, 11, 1394, 11, 1489, 10, 1493, 10, 1520,
8, 1521, 8, 1878, 9, 1879, 9, 1906, 7, 1910, 7, 2005, 6, 2007, 6, 2032, 8, 2033, 8, 2034, 7, 2037, 6,
2038, 7, 2039, 6
};
var contributions3D = new Contribution3[p3D.Length / 9];
for (var i = 0; i < p3D.Length; i += 9)
{
var baseSet = base3D[p3D[i]];
Contribution3 previous = null, current = null;
for (var k = 0; k < baseSet.Length; k += 4)
{
current = new Contribution3(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3]);
if (previous == null)
contributions3D[i / 9] = current;
else
previous.Next = current;
previous = current;
}
current.Next = new Contribution3(p3D[i + 1], p3D[i + 2], p3D[i + 3], p3D[i + 4]);
current.Next.Next = new Contribution3(p3D[i + 5], p3D[i + 6], p3D[i + 7], p3D[i + 8]);
}
lookup3D = new Contribution3[2048];
for (var i = 0; i < lookupPairs3D.Length; i += 2)
lookup3D[lookupPairs3D[i]] = contributions3D[lookupPairs3D[i + 1]];
var base4D = new[]
{
new[] { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0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3,
3, 0, 0, 2, 1, 3, 0, 0, 1, 2, 2, 1, -1, 1, 1, 3, 3, 0, 2, 1, 0, 3, 0, 1, 2, 0, 2, -1, 1, 1, 1, 3, 3, 0,
2, 0, 1, 3, 0, 1, 0, 2, 2, -1, 1, 1, 1, 3, 3, 0, 0, 2, 1, 3, 0, 0, 1, 2, 2, -1, 1, 1, 1
};
var lookupPairs4D = new[]
{
0, 3, 1, 2, 2, 3, 5, 2, 6, 1, 7, 1, 8, 3, 9, 2, 10, 3, 13, 2, 16, 3, 18, 3, 22, 1, 23, 1, 24, 3, 26, 3,
33, 2, 37, 2, 38, 1, 39, 1, 41, 2, 45, 2, 54, 1, 55, 1, 56, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0,
63, 0, 256, 3, 258, 3, 264, 3, 266, 3, 272, 3, 274, 3, 280, 3, 282, 3, 2049, 2, 2053, 2, 2057, 2, 2061,
2, 2081, 2, 2085, 2, 2089, 2, 2093, 2, 2304, 9, 2305, 9, 2312, 9, 2313, 9, 16390, 1, 16391, 1, 16406, 1,
16407, 1, 16422, 1, 16423, 1, 16438, 1, 16439, 1, 16642, 8, 16646, 8, 16658, 8, 16662, 8, 18437, 6,
18439, 6, 18469, 6, 18471, 6, 18688, 9, 18689, 9, 18690, 8, 18693, 6, 18694, 8, 18695, 6, 18696, 9,
18697, 9, 18706, 8, 18710, 8, 18725, 6, 18727, 6, 131128, 0, 131129, 0, 131130, 0, 131131, 0, 131132, 0,
131133, 0, 131134, 0, 131135, 0, 131352, 7, 131354, 7, 131384, 7, 131386, 7, 133161, 5, 133165, 5,
133177, 5, 133181, 5, 133376, 9, 133377, 9, 133384, 9, 133385, 9, 133400, 7, 133402, 7, 133417, 5,
133421, 5, 133432, 7, 133433, 5, 133434, 7, 133437, 5, 147510, 4, 147511, 4, 147518, 4, 147519, 4,
147714, 8, 147718, 8, 147730, 8, 147734, 8, 147736, 7, 147738, 7, 147766, 4, 147767, 4, 147768, 7,
147770, 7, 147774, 4, 147775, 4, 149509, 6, 149511, 6, 149541, 6, 149543, 6, 149545, 5, 149549, 5,
149558, 4, 149559, 4, 149561, 5, 149565, 5, 149566, 4, 149567, 4, 149760, 9, 149761, 9, 149762, 8,
149765, 6, 149766, 8, 149767, 6, 149768, 9, 149769, 9, 149778, 8, 149782, 8, 149784, 7, 149786, 7,
149797, 6, 149799, 6, 149801, 5, 149805, 5, 149814, 4, 149815, 4, 149816, 7, 149817, 5, 149818, 7,
149821, 5, 149822, 4, 149823, 4, 149824, 37, 149825, 37, 149826, 36, 149829, 34, 149830, 36, 149831, 34,
149832, 37, 149833, 37, 149842, 36, 149846, 36, 149848, 35, 149850, 35, 149861, 34, 149863, 34, 149865,
33, 149869, 33, 149878, 32, 149879, 32, 149880, 35, 149881, 33, 149882, 35, 149885, 33, 149886, 32,
149887, 32, 150080, 49, 150082, 48, 150088, 49, 150098, 48, 150104, 47, 150106, 47, 151873, 46, 151877,
45, 151881, 46, 151909, 45, 151913, 44, 151917, 44, 152128, 49, 152129, 46, 152136, 49, 152137, 46,
166214, 43, 166215, 42, 166230, 43, 166247, 42, 166262, 41, 166263, 41, 166466, 48, 166470, 43, 166482,
48, 166486, 43, 168261, 45, 168263, 42, 168293, 45, 168295, 42, 168512, 31, 168513, 28, 168514, 31,
168517, 28, 168518, 25, 168519, 25, 280952, 40, 280953, 39, 280954, 40, 280957, 39, 280958, 38, 280959,
38, 281176, 47, 281178, 47, 281208, 40, 281210, 40, 282985, 44, 282989, 44, 283001, 39, 283005, 39,
283208, 30, 283209, 27, 283224, 30, 283241, 27, 283256, 22, 283257, 22, 297334, 41, 297335, 41, 297342,
38, 297343, 38, 297554, 29, 297558, 24, 297562, 29, 297590, 24, 297594, 21, 297598, 21, 299365, 26,
299367, 23, 299373, 26, 299383, 23, 299389, 20, 299391, 20, 299584, 31, 299585, 28, 299586, 31, 299589,
28, 299590, 25, 299591, 25, 299592, 30, 299593, 27, 299602, 29, 299606, 24, 299608, 30, 299610, 29,
299621, 26, 299623, 23, 299625, 27, 299629, 26, 299638, 24, 299639, 23, 299640, 22, 299641, 22, 299642,
21, 299645, 20, 299646, 21, 299647, 20, 299648, 61, 299649, 60, 299650, 61, 299653, 60, 299654, 59,
299655, 59, 299656, 58, 299657, 57, 299666, 55, 299670, 54, 299672, 58, 299674, 55, 299685, 52, 299687,
51, 299689, 57, 299693, 52, 299702, 54, 299703, 51, 299704, 56, 299705, 56, 299706, 53, 299709, 50,
299710, 53, 299711, 50, 299904, 61, 299906, 61, 299912, 58, 299922, 55, 299928, 58, 299930, 55, 301697,
60, 301701, 60, 301705, 57, 301733, 52, 301737, 57, 301741, 52, 301952, 79, 301953, 79, 301960, 76,
301961, 76, 316038, 59, 316039, 59, 316054, 54, 316071, 51, 316086, 54, 316087, 51, 316290, 78, 316294,
78, 316306, 73, 316310, 73, 318085, 77, 318087, 77, 318117, 70, 318119, 70, 318336, 79, 318337, 79,
318338, 78, 318341, 77, 318342, 78, 318343, 77, 430776, 56, 430777, 56, 430778, 53, 430781, 50, 430782,
53, 430783, 50, 431000, 75, 431002, 72, 431032, 75, 431034, 72, 432809, 74, 432813, 69, 432825, 74,
432829, 69, 433032, 76, 433033, 76, 433048, 75, 433065, 74, 433080, 75, 433081, 74, 447158, 71, 447159,
68, 447166, 71, 447167, 68, 447378, 73, 447382, 73, 447386, 72, 447414, 71, 447418, 72, 447422, 71,
449189, 70, 449191, 70, 449197, 69, 449207, 68, 449213, 69, 449215, 68, 449408, 67, 449409, 67, 449410,
66, 449413, 64, 449414, 66, 449415, 64, 449416, 67, 449417, 67, 449426, 66, 449430, 66, 449432, 65,
449434, 65, 449445, 64, 449447, 64, 449449, 63, 449453, 63, 449462, 62, 449463, 62, 449464, 65, 449465,
63, 449466, 65, 449469, 63, 449470, 62, 449471, 62, 449472, 19, 449473, 19, 449474, 18, 449477, 16,
449478, 18, 449479, 16, 449480, 19, 449481, 19, 449490, 18, 449494, 18, 449496, 17, 449498, 17, 449509,
16, 449511, 16, 449513, 15, 449517, 15, 449526, 14, 449527, 14, 449528, 17, 449529, 15, 449530, 17,
449533, 15, 449534, 14, 449535, 14, 449728, 19, 449729, 19, 449730, 18, 449734, 18, 449736, 19, 449737,
19, 449746, 18, 449750, 18, 449752, 17, 449754, 17, 449784, 17, 449786, 17, 451520, 19, 451521, 19,
451525, 16, 451527, 16, 451528, 19, 451529, 19, 451557, 16, 451559, 16, 451561, 15, 451565, 15, 451577,
15, 451581, 15, 451776, 19, 451777, 19, 451784, 19, 451785, 19, 465858, 18, 465861, 16, 465862, 18,
465863, 16, 465874, 18, 465878, 18, 465893, 16, 465895, 16, 465910, 14, 465911, 14, 465918, 14, 465919,
14, 466114, 18, 466118, 18, 466130, 18, 466134, 18, 467909, 16, 467911, 16, 467941, 16, 467943, 16,
468160, 13, 468161, 13, 468162, 13, 468163, 13, 468164, 13, 468165, 13, 468166, 13, 468167, 13, 580568,
17, 580570, 17, 580585, 15, 580589, 15, 580598, 14, 580599, 14, 580600, 17, 580601, 15, 580602, 17,
580605, 15, 580606, 14, 580607, 14, 580824, 17, 580826, 17, 580856, 17, 580858, 17, 582633, 15, 582637,
15, 582649, 15, 582653, 15, 582856, 12, 582857, 12, 582872, 12, 582873, 12, 582888, 12, 582889, 12,
582904, 12, 582905, 12, 596982, 14, 596983, 14, 596990, 14, 596991, 14, 597202, 11, 597206, 11, 597210,
11, 597214, 11, 597234, 11, 597238, 11, 597242, 11, 597246, 11, 599013, 10, 599015, 10, 599021, 10,
599023, 10, 599029, 10, 599031, 10, 599037, 10, 599039, 10, 599232, 13, 599233, 13, 599234, 13, 599235,
13, 599236, 13, 599237, 13, 599238, 13, 599239, 13, 599240, 12, 599241, 12, 599250, 11, 599254, 11,
599256, 12, 599257, 12, 599258, 11, 599262, 11, 599269, 10, 599271, 10, 599272, 12, 599273, 12, 599277,
10, 599279, 10, 599282, 11, 599285, 10, 599286, 11, 599287, 10, 599288, 12, 599289, 12, 599290, 11,
599293, 10, 599294, 11, 599295, 10
};
var contributions4D = new Contribution4[p4D.Length / 16];
for (var i = 0; i < p4D.Length; i += 16)
{
var baseSet = base4D[p4D[i]];
Contribution4 previous = null, current = null;
for (var k = 0; k < baseSet.Length; k += 5)
{
current = new Contribution4(baseSet[k], baseSet[k + 1], baseSet[k + 2], baseSet[k + 3],
baseSet[k + 4]);
if (previous == null)
contributions4D[i / 16] = current;
else
previous.Next = current;
previous = current;
}
current.Next = new Contribution4(p4D[i + 1], p4D[i + 2], p4D[i + 3], p4D[i + 4], p4D[i + 5]);
current.Next.Next = new Contribution4(p4D[i + 6], p4D[i + 7], p4D[i + 8], p4D[i + 9], p4D[i + 10]);
current.Next.Next.Next =
new Contribution4(p4D[i + 11], p4D[i + 12], p4D[i + 13], p4D[i + 14], p4D[i + 15]);
}
lookup4D = new Contribution4[1048576];
for (var i = 0; i < lookupPairs4D.Length; i += 2)
lookup4D[lookupPairs4D[i]] = contributions4D[lookupPairs4D[i + 1]];
}
public OpenSimplexNoise()
: this(DateTime.Now.Ticks)
{
}
public OpenSimplexNoise(long seed)
{
perm = new byte[256];
perm2D = new byte[256];
perm3D = new byte[256];
perm4D = new byte[256];
var source = new byte[256];
for (var i = 0; i < 256; i++) source[i] = (byte)i;
seed = seed * 6364136223846793005L + 1442695040888963407L;
seed = seed * 6364136223846793005L + 1442695040888963407L;
seed = seed * 6364136223846793005L + 1442695040888963407L;
for (var i = 255; i >= 0; i--)
{
seed = seed * 6364136223846793005L + 1442695040888963407L;
var r = (int)((seed + 31) % (i + 1));
if (r < 0) r += i + 1;
perm[i] = source[r];
perm2D[i] = (byte)(perm[i] & 0x0E);
perm3D[i] = (byte)(perm[i] % 24 * 3);
perm4D[i] = (byte)(perm[i] & 0xFC);
source[r] = source[i];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int FastFloor(double x)
{
var xi = (int)x;
return x < xi ? xi - 1 : xi;
}
public double Evaluate(double x, double y)
{
var stretchOffset = (x + y) * STRETCH_2D;
var xs = x + stretchOffset;
var ys = y + stretchOffset;
var xsb = FastFloor(xs);
var ysb = FastFloor(ys);
var squishOffset = (xsb + ysb) * SQUISH_2D;
var dx0 = x - (xsb + squishOffset);
var dy0 = y - (ysb + squishOffset);
var xins = xs - xsb;
var yins = ys - ysb;
var inSum = xins + yins;
var hash =
(int)(xins - yins + 1) |
((int)inSum << 1) |
((int)(inSum + yins) << 2) |
((int)(inSum + xins) << 4);
var c = lookup2D[hash];
var value = 0.0;
while (c != null)
{
var dx = dx0 + c.dx;
var dy = dy0 + c.dy;
var attn = 2 - dx * dx - dy * dy;
if (attn > 0)
{
var px = xsb + c.xsb;
var py = ysb + c.ysb;
var i = perm2D[(perm[px & 0xFF] + py) & 0xFF];
var valuePart = gradients2D[i] * dx + gradients2D[i + 1] * dy;
attn *= attn;
value += attn * attn * valuePart;
}
c = c.Next;
}
return value * NORM_2D;
}
public double Evaluate(double x, double y, double z)
{
var stretchOffset = (x + y + z) * STRETCH_3D;
var xs = x + stretchOffset;
var ys = y + stretchOffset;
var zs = z + stretchOffset;
var xsb = FastFloor(xs);
var ysb = FastFloor(ys);
var zsb = FastFloor(zs);
var squishOffset = (xsb + ysb + zsb) * SQUISH_3D;
var dx0 = x - (xsb + squishOffset);
var dy0 = y - (ysb + squishOffset);
var dz0 = z - (zsb + squishOffset);
var xins = xs - xsb;
var yins = ys - ysb;
var zins = zs - zsb;
var inSum = xins + yins + zins;
var hash =
(int)(yins - zins + 1) |
((int)(xins - yins + 1) << 1) |
((int)(xins - zins + 1) << 2) |
((int)inSum << 3) |
((int)(inSum + zins) << 5) |
((int)(inSum + yins) << 7) |
((int)(inSum + xins) << 9);
var c = lookup3D[hash];
var value = 0.0;
while (c != null)
{
var dx = dx0 + c.dx;
var dy = dy0 + c.dy;
var dz = dz0 + c.dz;
var attn = 2 - dx * dx - dy * dy - dz * dz;
if (attn > 0)
{
var px = xsb + c.xsb;
var py = ysb + c.ysb;
var pz = zsb + c.zsb;
var i = perm3D[(perm[(perm[px & 0xFF] + py) & 0xFF] + pz) & 0xFF];
var valuePart = gradients3D[i] * dx + gradients3D[i + 1] * dy + gradients3D[i + 2] * dz;
attn *= attn;
value += attn * attn * valuePart;
}
c = c.Next;
}
return value * NORM_3D;
}
public double Evaluate(double x, double y, double z, double w)
{
var stretchOffset = (x + y + z + w) * STRETCH_4D;
var xs = x + stretchOffset;
var ys = y + stretchOffset;
var zs = z + stretchOffset;
var ws = w + stretchOffset;
var xsb = FastFloor(xs);
var ysb = FastFloor(ys);
var zsb = FastFloor(zs);
var wsb = FastFloor(ws);
var squishOffset = (xsb + ysb + zsb + wsb) * SQUISH_4D;
var dx0 = x - (xsb + squishOffset);
var dy0 = y - (ysb + squishOffset);
var dz0 = z - (zsb + squishOffset);
var dw0 = w - (wsb + squishOffset);
var xins = xs - xsb;
var yins = ys - ysb;
var zins = zs - zsb;
var wins = ws - wsb;
var inSum = xins + yins + zins + wins;
var hash =
(int)(zins - wins + 1) |
((int)(yins - zins + 1) << 1) |
((int)(yins - wins + 1) << 2) |
((int)(xins - yins + 1) << 3) |
((int)(xins - zins + 1) << 4) |
((int)(xins - wins + 1) << 5) |
((int)inSum << 6) |
((int)(inSum + wins) << 8) |
((int)(inSum + zins) << 11) |
((int)(inSum + yins) << 14) |
((int)(inSum + xins) << 17);
var c = lookup4D[hash];
var value = 0.0;
while (c != null)
{
var dx = dx0 + c.dx;
var dy = dy0 + c.dy;
var dz = dz0 + c.dz;
var dw = dw0 + c.dw;
var attn = 2 - dx * dx - dy * dy - dz * dz - dw * dw;
if (attn > 0)
{
var px = xsb + c.xsb;
var py = ysb + c.ysb;
var pz = zsb + c.zsb;
var pw = wsb + c.wsb;
var i = perm4D[(perm[(perm[(perm[px & 0xFF] + py) & 0xFF] + pz) & 0xFF] + pw) & 0xFF];
var valuePart = gradients4D[i] * dx + gradients4D[i + 1] * dy + gradients4D[i + 2] * dz +
gradients4D[i + 3] * dw;
attn *= attn;
value += attn * attn * valuePart;
}
c = c.Next;
}
return value * NORM_4D;
}
private class Contribution2
{
public readonly double dx;
public readonly double dy;
public Contribution2 Next;
public readonly int xsb;
public readonly int ysb;
public Contribution2(double multiplier, int xsb, int ysb)
{
dx = -xsb - multiplier * SQUISH_2D;
dy = -ysb - multiplier * SQUISH_2D;
this.xsb = xsb;
this.ysb = ysb;
}
}
private class Contribution3
{
public readonly double dx;
public readonly double dy;
public readonly double dz;
public Contribution3 Next;
public readonly int xsb;
public readonly int ysb;
public readonly int zsb;
public Contribution3(double multiplier, int xsb, int ysb, int zsb)
{
dx = -xsb - multiplier * SQUISH_3D;
dy = -ysb - multiplier * SQUISH_3D;
dz = -zsb - multiplier * SQUISH_3D;
this.xsb = xsb;
this.ysb = ysb;
this.zsb = zsb;
}
}
private class Contribution4
{
public readonly double dx;
public readonly double dy;
public readonly double dz;
public readonly double dw;
public Contribution4 Next;
public readonly int xsb;
public readonly int ysb;
public readonly int zsb;
public readonly int wsb;
public Contribution4(double multiplier, int xsb, int ysb, int zsb, int wsb)
{
dx = -xsb - multiplier * SQUISH_4D;
dy = -ysb - multiplier * SQUISH_4D;
dz = -zsb - multiplier * SQUISH_4D;
dw = -wsb - multiplier * SQUISH_4D;
this.xsb = xsb;
this.ysb = ysb;
this.zsb = zsb;
this.wsb = wsb;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a7d7a0770e6524340b8802716bbeab16
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7e9d16dac388c694c80dc8adb8d4d77b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/Scripts/Player/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c1aca789321cc19488a218ef5028c73b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,28 @@
using UnityEngine;
namespace Player.Information
{
public class PlayerDialogue : MonoBehaviour
{
public GameObject dialogueMaster;
private GameObject chatHolder;
private GameObject chatPrompt;
private void Start()
{
chatHolder = dialogueMaster.transform.Find("Chat Holder").gameObject;
chatPrompt = dialogueMaster.transform.Find("Chat Prompt").gameObject;
chatHolder.SetActive(false);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.LeftAlt))
{
chatHolder.SetActive(!chatHolder.activeSelf);
chatPrompt.SetActive(!chatPrompt.activeSelf);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dc09d3a52bf3249bca6ecf5691ea62e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,154 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Player.Movement;
namespace Player.Information
{
public class PlayerStats : MonoBehaviour
{
[SerializeField] private float maxHealth = 100;
[SerializeField] private float healthDepleteRate = 1;
[SerializeField] private float maxHunger = 20f;
[SerializeField] private float maxHydration = 10f;
[SerializeField] private int nanites = 10;
[SerializeField] private Transform spawnpoint;
[SerializeField] public bool jetpackEnabled;
[SerializeField] public bool inputEnabled = true;
public bool grappleEnabled;
private float health;
private Image healthContent;
private float hunger;
private Image hungerContent;
private float hydration;
private Image hydrationContent;
private TMP_Text naniteContent;
private PlayerPhysics playerPhysics;
private GameObject statUI;
private Image thrustContent;
// Start is called before the first frame update
private void Start()
{
health = maxHealth;
hunger = maxHunger;
hydration = maxHydration;
statUI = GameObject.Find("Survival Stats");
healthContent = statUI.transform.Find("Health Bar/Health Value").gameObject.GetComponent<Image>();
hungerContent = statUI.transform.Find("Hunger Bar/Hunger Value").gameObject.GetComponent<Image>();
hydrationContent = statUI.transform.Find("Hydration Bar/Hydration Value").gameObject.GetComponent<Image>();
naniteContent = statUI.transform.Find("Nanite Bar").gameObject.GetComponent<TMP_Text>();
thrustContent = statUI.transform.Find("Thrust Bar/Thrust Value").gameObject.GetComponent<Image>();
SetNanites(nanites);
playerPhysics = gameObject.GetComponent<PlayerPhysics>();
}
// Update is called once per frame
private void Update()
{
TickStats();
}
//called each frame to update stat values
public void TickStats()
{
TickHunger();
TickHydration();
if (hunger == 0f || hydration == 0f) ChangeHealth(-healthDepleteRate * Time.deltaTime);
if (health == 0)
{
Debug.Log("player died");
Respawn();
}
}
public void ChangeStat(ref float stat, float maxStat, float change, ref Image statContent)
{
stat = Mathf.Clamp(stat + change, 0f, maxStat);
statContent.fillAmount = Mathf.Clamp(stat / maxStat, 0f, 1f);
}
public void TickHunger()
{
ChangeHunger(-Time.deltaTime);
}
public void TickHydration()
{
ChangeHydration(-Time.deltaTime);
}
public void ChangeHealth(float change)
{
ChangeStat(ref health, maxHealth, change, ref healthContent);
}
public void ChangeHunger(float change)
{
ChangeStat(ref hunger, maxHunger, change, ref hungerContent);
}
public void ChangeHydration(float change)
{
ChangeStat(ref hydration, maxHydration, change, ref hydrationContent);
}
public void ConsumeResource(float change, string name)
{
if (name == "Food")
ChangeHunger(change);
else if (name == "Water")
ChangeHydration(change);
else if (name == "Health") ChangeHealth(change);
}
public int GetNanites()
{
return nanites;
}
public void SetNanites(int s)
{
nanites = s;
naniteContent.SetText(nanites.ToString());
}
public void ChangeNanites(int c)
{
SetNanites(nanites + c);
}
public void Respawn()
{
// Note, this respawn script will have to be more advanced in later versions.
ChangeHealth(maxHealth);
ChangeHunger(maxHunger);
ChangeHydration(maxHydration);
transform.position = spawnpoint.position;
transform.rotation = spawnpoint.rotation;
playerPhysics.Reset();
}
public void SetThrust(float amount)
{
thrustContent.fillAmount = amount;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b0d818a45884a4068a5ac6a6cbdb184e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aa3116809fe12c44594680a2846a99e9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,53 @@
using UnityEngine;
namespace Player.Interactions
{
public class ConstructMenuItem
{
private readonly string desc;
private readonly Sprite image;
private readonly string name;
private readonly GameObject target;
public ConstructMenuItem(string name, Sprite image, string desc)
{
this.name = name;
this.image = image;
this.desc = desc;
target = null;
}
public ConstructMenuItem(string name, Sprite image, string desc, GameObject target)
{
this.name = name;
this.image = image;
int cost = target.GetComponent<ConstructBase>().GetCost();
if (cost == 1)
this.desc = desc + "\nCosts " + cost + " Nanite.";
else
this.desc = desc + "\nCosts " + cost + " Nanites.";
this.target = target;
}
public string GetName()
{
return name;
}
public Sprite GetImage()
{
return image;
}
public string GetDesc()
{
return desc;
}
public GameObject GetTarget()
{
return target;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c019fe381690348c59444c8294aa15d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,100 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using Player.Information;
namespace Player.Interactions
{
public class ConstructSelector : MonoBehaviour
{
public GameObject foodMakerPrefab;
public GameObject player;
public Sprite foodMakerImage;
public GameObject waterMakerPrefab;
public Sprite waterMakerImage;
public GameObject healthAreaPrefab;
public Sprite healthAreaImage;
public Image constructImage;
public GameObject selectedImage;
public GameObject unselectedArrow;
private readonly List<ConstructMenuItem> choices = new();
public TMP_Text constructDesc;
public TMP_Text constructName;
private int currentIndex;
private int selectedIndex;
private PlayerStats playerStats;
// Start is called before the first frame update
private void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
playerStats = player.GetComponent<PlayerStats>();
choices.Add(new ConstructMenuItem("Nutrient Consolidator", foodMakerImage,
"Scrapes nutrients from the ground to make food.\n\nRelies on local biodensity.", foodMakerPrefab));
choices.Add(new ConstructMenuItem("Water Condenser", waterMakerImage,
"Condenses vapor from the atmosphere to make water.\n\nRelies on local humidity.", waterMakerPrefab));
choices.Add(new ConstructMenuItem("Regeneration Field", healthAreaImage,
"Distributes nanites onto organisms to repair tissue.\n\nRequires proximity.", healthAreaPrefab));
currentIndex = 0;
selectedIndex = 0;
RenderPanel();
}
// Update is called once per frame
private void Update()
{
if (Input.GetKeyDown(KeyCode.LeftArrow) )
{
currentIndex--;
if (currentIndex < 0) currentIndex = choices.Count - 1;
RenderPanel();
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
currentIndex++;
if (currentIndex >= choices.Count) currentIndex = 0;
RenderPanel();
}
if (Input.GetKeyDown(KeyCode.UpArrow) )
{
selectedIndex = currentIndex;
RenderPanel();
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
}
}
public void RenderPanel()
{
constructName.SetText(choices[currentIndex].GetName());
constructImage.sprite = choices[currentIndex].GetImage();
constructDesc.SetText(choices[currentIndex].GetDesc());
if (selectedIndex == currentIndex)
{
selectedImage.SetActive(true);
unselectedArrow.SetActive(false);
}
else
{
selectedImage.SetActive(false);
unselectedArrow.SetActive(true);
}
}
public GameObject GetSelected()
{
return choices[selectedIndex].GetTarget();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 21a3bcb112beb4f3f8aa38fc58a2c67d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,119 @@
using UnityEngine;
using Player.Information;
namespace Player.Interactions
{
public class GrappleHook : MonoBehaviour
{
[SerializeField] private float maxGrappleThrow;
[SerializeField] private float grappleStrength;
[SerializeField] public float grappledAirControl;
[SerializeField] private GameObject grapplePointPrefab;
public bool grappled;
[SerializeField] private LineRenderer lineRender;
public GameObject reticleMaster;
private GameObject curPointObj;
private Vector3 grapplePos;
private PlayerStats playerStats;
private GameObject reticleClose;
private GameObject reticleOpen;
// Start is called before the first frame update
private void Start()
{
grappled = false;
grapplePos = Vector3.zero;
lineRender.enabled = false;
reticleOpen = reticleMaster.transform.Find("Reticle Open").gameObject;
reticleClose = reticleMaster.transform.Find("Reticle Close").gameObject;
reticleClose.SetActive(false);
playerStats = gameObject.GetComponent<PlayerStats>();
}
// Update is called once per frame
private void Update()
{
if (playerStats.grappleEnabled)
{
if (WouldGrapple())
{
reticleOpen.SetActive(false);
reticleClose.SetActive(true);
}
else
{
reticleOpen.SetActive(true);
reticleClose.SetActive(false);
}
if ((Input.GetKeyDown(KeyCode.L) || Input.GetMouseButtonDown(0)) ) ShootGrapple();
if ((Input.GetKeyDown(KeyCode.K) || Input.GetMouseButtonUp(0)) ) ReleaseGrapple();
if (grappled)
{
lineRender.SetPosition(0, gameObject.transform.position);
lineRender.SetPosition(1, grapplePos);
}
}
}
public bool WouldGrapple()
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit,
maxGrappleThrow))
{
TraversalProperties tp = hit.collider.gameObject.GetComponent<TraversalProperties>();
if (tp == null || tp.canGrappleOnto) return true;
}
return false;
}
public void ShootGrapple()
{
// perform a raycast from the player's reticle
RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit,
maxGrappleThrow))
{
//Debug.DrawRay(Camera.main.transform.position, hit.point, Color.green, 5f);
TraversalProperties tp = hit.collider.gameObject.GetComponent<TraversalProperties>();
if (tp == null || tp.canGrappleOnto)
{
grappled = true;
grapplePos = hit.point;
if (curPointObj != null) Destroy(curPointObj);
curPointObj = Instantiate(grapplePointPrefab, hit.point, Quaternion.identity);
lineRender.enabled = true;
}
}
}
public void ReleaseGrapple()
{
grappled = false;
grapplePos = Vector3.zero;
if (curPointObj != null) Destroy(curPointObj);
lineRender.enabled = false;
}
public Vector3 PullForce(Vector3 playerPos)
{
if (!grappled)
return Vector3.zero;
return (grapplePos - playerPos).normalized * grappleStrength;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3e7f9353d2ac547538de04c5e5988dd0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,92 @@
using UnityEngine;
using Player.Movement;
using Player.Information;
namespace Player.Interactions
{
public class JetPack : MonoBehaviour
{
// in Newtons
[SerializeField] private float thrustStrength;
// in seconds
[SerializeField] private float maxLoftTime;
// in seconds per seconds
[SerializeField] private float loftReclaimRate;
[SerializeField] private float airLoftReclaimRate;
// particle system for jetpack
[SerializeField] private ParticleSystem flames;
private bool active;
private float loftTime;
private PlayerPhysics playerPhysics;
private PlayerStats playerStats;
private void Start()
{
SetActiveThrust(false);
loftTime = maxLoftTime;
playerPhysics = gameObject.GetComponent<PlayerPhysics>();
playerStats = gameObject.GetComponent<PlayerStats>();
}
private void Update()
{
if (playerStats.jetpackEnabled)
{
if (Input.GetKey(KeyCode.Q) )
{
if (loftTime > 0f)
{
SetActiveThrust(true);
loftTime = Mathf.Max(0f, loftTime - Time.deltaTime);
}
else
{
SetActiveThrust(false);
}
}
else
{
SetActiveThrust(false);
if (loftTime < maxLoftTime)
{
if (playerPhysics.isGrounded())
loftTime = Mathf.Min(maxLoftTime, loftTime + loftReclaimRate * Time.deltaTime);
else
loftTime = Mathf.Min(maxLoftTime, loftTime + airLoftReclaimRate * Time.deltaTime);
}
}
playerStats.SetThrust(loftTime / maxLoftTime);
}
}
public Vector3 ThrustForce()
{
if (active)
return new Vector3(0f, thrustStrength, 0f);
return Vector3.zero;
}
private void SetActiveThrust(bool state)
{
active = state;
SetEmission(state);
}
private void SetEmission(bool state)
{
var emission = flames.emission;
emission.enabled = state;
}
public void ResetThrust()
{
loftTime = maxLoftTime;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d8d226b0302f94fd38153b488954c2b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,117 @@
using UnityEngine;
using Player.Information;
using Player.Interactions;
public class PlayerInteractions : MonoBehaviour
{
[SerializeField] private float maxInteractDistance = 1f;
public GameObject selectionMaster;
public GameObject multiToolModel;
private ConstructSelector cs;
private PlayerStats playerStats;
private GameObject selectionHolder;
private GameObject selectionPrompt;
// Start is called before the first frame update
private void Start()
{
playerStats = gameObject.GetComponent<PlayerStats>();
//cs.gameObject.SetActive(false);
selectionHolder = selectionMaster.transform.Find("Selection Holder").gameObject;
selectionPrompt = selectionMaster.transform.Find("Selection Prompt").gameObject;
cs = selectionHolder.GetComponent<ConstructSelector>();
selectionHolder.SetActive(false);
multiToolModel.SetActive(false);
//Screen.fullScreenMode = FullScreenMode.ExclusiveFullScreen;
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
private void Update()
{
if (Input.GetKeyDown(KeyCode.R) )
{
Debug.Log("R Pressed");
InteractWithObject();
}
/*
if (Input.GetKeyDown(KeyCode.Q))
{
DisassembleObject();
}
*/
if (Input.GetKeyDown(KeyCode.E) )
{
DisassembleObject();
PlaceObject();
}
if (Input.GetKeyDown(KeyCode.Tab) )
{
selectionHolder.SetActive(!selectionHolder.activeSelf);
selectionPrompt.SetActive(!selectionPrompt.activeSelf);
multiToolModel.SetActive(!multiToolModel.activeSelf);
}
}
public void InteractWithObject()
{
RaycastHit hit;
Debug.Log("interact");
//Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward, Color.green, 3f);
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit,
maxInteractDistance))
{
Debug.Log(hit.collider.gameObject);
//Debug.DrawRay(Camera.main.transform.position, hit.point, Color.green, 5f);
if (hit.collider.gameObject.tag == "Construct")
{
ConstructMaker maker = hit.collider.gameObject.GetComponent<ConstructMaker>();
if (maker != null)
{
float change = maker.Interact();
playerStats.ConsumeResource(change, maker.GetResource());
}
}
if (hit.collider.gameObject.tag == "Key") hit.collider.gameObject.SetActive(false);
}
}
public void DisassembleObject()
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit,
maxInteractDistance))
if (hit.collider.gameObject.tag == "Construct")
{
int reward = hit.collider.gameObject.GetComponent<ConstructBase>().Disassemble();
playerStats.ChangeNanites(reward);
}
}
public void PlaceObject()
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit,
maxInteractDistance))
if (Vector3.Normalize(hit.normal) == Vector3.up && hit.collider.gameObject.tag != "Construct")
{
GameObject selectedConstruct = cs.GetSelected();
int cost = selectedConstruct.GetComponent<ConstructBase>().GetCost();
if (cost <= playerStats.GetNanites())
{
var construct = Instantiate(selectedConstruct, hit.point + Vector3.up * 0.3f, Quaternion.identity);
playerStats.ChangeNanites(-cost);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8444a0389c8844a89130facf25837a9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 15c4dba372dd94727b6dfe262983c56f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MetaMenu : MonoBehaviour
{
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
SceneManager.LoadScene("MainMenu");
}
if (Input.GetKeyDown(KeyCode.F))
{
Screen.fullScreen = !Screen.fullScreen;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 41353f2b6e88a4e6b84c0c56caade718
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b6667fe3441725a458384c6b95941381
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,47 @@
using UnityEngine;
namespace Player.Movement
{
public class MouseLook : MonoBehaviour
{
[SerializeField] public float mouseSensitivity = 100f;
public float xRotation;
private Transform playerBody;
// Start is called before the first frame update
private void Start()
{
// check playerprefs for sensitivity
// if not set, set to 100
// if set, set to playerprefs
if (!PlayerPrefs.HasKey("Sensitivity"))
{
PlayerPrefs.SetFloat("Sensitivity", 100f);
}
else
{
mouseSensitivity = PlayerPrefs.GetFloat("Sensitivity");
}
playerBody = transform.parent;
Cursor.lockState = CursorLockMode.Locked;
//mouseSensitivity = PlayerPrefs.GetFloat("Sensitivity");
}
// Update is called once per frame
private void Update()
{
var mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
var mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
playerBody.Rotate(Vector3.up * mouseX);
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 867f6d1560c5c4838bf513a400b50bec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,67 @@
using UnityEngine;
using Player.Interactions;
public class PlayerMovement : MonoBehaviour
{
// Start is called before the first frame update
private void Start()
{
_controller = gameObject.GetComponent<CharacterController>();
_moveSpeed = walkSpeed;
_sprintBonus = sprintSpeed - walkSpeed;
grappleHook = gameObject.GetComponent<GrappleHook>();
}
// Update is called once per frame
private void Update()
{
// ground check
// isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
_isGrounded = _controller.isGrounded;
if (_isGrounded && playerVelocity.y < 0) playerVelocity.y = -2f;
// sprint mechanic
var sprintInput = Input.GetAxis("Sprint");
// wasd player movement
var xMove = Input.GetAxis("Horizontal");
var zMove = Input.GetAxis("Vertical");
var xzMove = (transform.right * xMove + transform.forward * zMove) * (_moveSpeed + sprintInput * _sprintBonus);
// jump
if (Input.GetButtonDown("Jump") && _isGrounded) playerVelocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
// gravity
playerVelocity.y += gravity * Time.deltaTime;
// force applied by grapple hook
//playerVelocity += grappleHook.PullForce(transform.position) * Time.deltaTime;
// final player move
_controller.Move((playerVelocity + xzMove) * Time.deltaTime);
//Debug.Log(controller.isGrounded);
}
#region Variables
[SerializeField] private float walkSpeed = 2f;
[SerializeField] private float sprintSpeed = 10f;
private float _moveSpeed;
private float _sprintBonus;
private CharacterController _controller;
public Vector3 playerVelocity;
[SerializeField] private float jumpHeight = 2f;
[SerializeField] private float gravity = -10f;
private bool _isGrounded;
private GrappleHook grappleHook;
#endregion
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3ecedebba2564ed7ad0bca94c48c9a0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,149 @@
using UnityEngine;
public class PlayerMovement2 : MonoBehaviour
{
// Start is called before the first frame update
private void Start()
{
controller = gameObject.GetComponent<CharacterController>();
playerVelocity = Vector3.zero;
playerAcceleration = Vector3.zero;
moveSpeed = walkSpeed;
sprintBonus = sprintSpeed - walkSpeed;
}
private void Update()
{
// acceleration of an object by default is zero
playerAcceleration = Vector3.zero;
// determine if the player is grounded
isGrounded = controller.isGrounded;
playerAcceleration += new Vector3(0f, gravity, 0f);
// add acceleration due to normal force, assuming platforms are stationary and parallel to the ground
if (isGrounded) playerAcceleration += new Vector3(0f, -gravity, 0f);
// when the player jumps on the ground, apply an instant force to the player's velocity
if (isGrounded && Input.GetButtonDown("Jump")) playerAcceleration.y += jumpHeight;
// handle force applied by player movement
if (isGrounded)
if (playerVelocity.magnitude < maxWalkSpeed)
{
//Vector3 xzMove = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
var xzMove = Vector3.zero;
if (Input.GetKey(KeyCode.W)) xzMove.z += 1f;
if (Input.GetKey(KeyCode.S)) xzMove.z += -1f;
if (Input.GetKey(KeyCode.D)) xzMove.x += 1f;
if (Input.GetKey(KeyCode.A)) xzMove.x += -1f;
xzMove = xzMove.normalized * moveSpeed;
var transformedDisplacement = transform.right * xzMove.x + transform.forward * xzMove.z;
playerAcceleration += transformedDisplacement;
}
// add acceleration due to friction
if (isGrounded)
{
var forceByFriction = Vector3.ProjectOnPlane(playerVelocity.normalized, transform.up) * frictionDefault;
playerAcceleration -= forceByFriction;
}
// add to player's velocity based on acceleartion
playerVelocity += playerAcceleration * Time.deltaTime;
/*
// assume all platforms are stationary and parallel to the ground
if (isGrounded && playerVelocity.y < 0)
{
playerVelocity.y = 0f;
}
// when the player jumps on the ground, apply an instant force to the player's velocity
if (isGrounded && Input.GetButtonDown("Jump"))
{
playerVelocity.y += Mathf.Sqrt(jumpHeight * -2f * gravity);
}
// apply an instant force to the player's velocity when on the ground when they try to move
if (isGrounded)
{
if (playerVelocity.magnitude < maxWalkSpeed)
{
Vector3 xzMove = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
xzMove = xzMove.normalized * moveSpeed * Time.deltaTime;
playerVelocity += transform.right * xzMove.x + transform.forward * xzMove.z;
}
}
*/
// add to the player's position based on velocity
controller.Move(playerVelocity * Time.deltaTime);
Debug.Log(playerVelocity.magnitude);
}
#region Variables
[SerializeField] private float walkSpeed = 2f;
[SerializeField] private float maxWalkSpeed = 10f;
[SerializeField] private float sprintSpeed = 10f;
private float moveSpeed;
private float sprintBonus;
[SerializeField] private float jumpHeight = 2f;
[SerializeField] private float gravity = -10f;
[SerializeField] private float frictionDefault = 1f;
private CharacterController controller;
public Vector3 playerVelocity;
public Vector3 playerAcceleration;
private bool isGrounded;
#endregion
/*
// Update is called once per frame
void Update()
{
// ground check
// isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
isGrounded = controller.isGrounded;
if (isGrounded && playerVelocity.y < 0)
{
playerVelocity.y = -2f;
}
// sprint mechanic
float sprintInput = Input.GetAxis("Sprint");
// wasd player movement
float xMove = Input.GetAxis("Horizontal");
float zMove = Input.GetAxis("Vertical");
Vector3 xzMove = (transform.right * xMove + transform.forward * zMove) * (moveSpeed + sprintInput * sprintBonus);
// jump
if (Input.GetButtonDown("Jump") && isGrounded)
{
playerVelocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
// gravity
playerVelocity.y += gravity * Time.deltaTime;
// final player move
controller.Move((playerVelocity + xzMove) * Time.deltaTime);
//Debug.Log(controller.isGrounded);
}
*/
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8682b16961bcd049923fff1bdc4126d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,78 @@
using UnityEngine;
using Player.Interactions;
public class PlayerMovement3 : MonoBehaviour
{
// Start is called before the first frame update
private void Start()
{
_controller = gameObject.GetComponent<CharacterController>();
_moveSpeed = walkSpeed;
_sprintBonus = sprintSpeed - walkSpeed;
grappleHook = gameObject.GetComponent<GrappleHook>();
}
// Update is called once per frame
private void Update()
{
// an object by default has no forces acting on it, and therefore, zero acceleration
playerAcceleration = Vector3.zero;
// acceleration due to gravity
playerAcceleration += new Vector3(0f, gravity, 0f);
// ground check
_isGrounded = _controller.isGrounded;
// assuming platforms are horizontal and stationary
if (_isGrounded && playerVelocity.y < 0) playerVelocity.y = -2f;
// instant force applied on jump
if (Input.GetButtonDown("Jump") && _isGrounded) playerVelocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
// sprint mechanic
var sprintInput = Input.GetAxis("Sprint");
// wasd player movement
var xMove = Input.GetAxis("Horizontal");
var zMove = Input.GetAxis("Vertical");
var transformedMove = transform.right * xMove + transform.forward * zMove;
if (transformedMove.magnitude > 1f) transformedMove = transformedMove.normalized;
var xzMove = transformedMove * (_moveSpeed + sprintInput * _sprintBonus);
// instance force applied when moving
_controller.Move(xzMove * Time.deltaTime);
// force applied by grapple hook
//playerVelocity += grappleHook.PullForce(transform.position) * Time.deltaTime;
// apply acceleration to player velocity
playerVelocity += playerAcceleration * Time.deltaTime;
// apply velocity to change position
_controller.Move(playerVelocity * Time.deltaTime);
//Debug.Log(controller.isGrounded);
}
#region Variables
[SerializeField] private float walkSpeed = 2f;
[SerializeField] private float sprintSpeed = 10f;
private float _moveSpeed;
private float _sprintBonus;
private CharacterController _controller;
public Vector3 playerAcceleration;
public Vector3 playerVelocity;
[SerializeField] private float jumpHeight = 2f;
[SerializeField] private float gravity = -10f;
private bool _isGrounded;
private GrappleHook grappleHook;
#endregion
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9c4fb8c78ea7749a3a9e88c9ae55e131
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,208 @@
using Player.Interactions;
using UnityEngine;
using Player.Information;
namespace Player.Movement
{
public class PlayerPhysics : MonoBehaviour
{
// measured in meters per second squared
[SerializeField] private Vector3 gravity;
[SerializeField] private float walkingForce;
[SerializeField] private float maxWalkSpeed;
[SerializeField] private float maxRunSpeed;
// measured in N applied when space is pressed
[SerializeField] private float jumpForce;
[SerializeField] private float defaultAirControl;
// the minimum change in speed which will result in damage being taken
[SerializeField] private float speedDamageThreshold;
// the ratio of speed change to damage taken
[SerializeField] private float speedToDamage;
// measured in seconds
[SerializeField] private float coyoteTime;
[SerializeField] private float jumpBuffer;
// current air control ratio experienced by the player
private float airControl;
private float coyoteTimeCounter;
// reference to GrappleHook script
private GrappleHook grappleHook;
// reference to JetPack script
private JetPack jetPack;
private float jumpBufferCounter;
// current maximum input speed of the player
private float maxSpeed;
// referendce to PlayerStats script
private PlayerStats playerStats;
// metrics for ground detection
//private float playerHeight;
//private Vector3 boxDim;
// speed of the player in the previous frame
private float prevFrameSpeed;
private Rigidbody rb;
public void Reset()
{
prevFrameSpeed = 0f;
rb.velocity = Vector3.zero;
grappleHook.ReleaseGrapple();
jetPack.ResetThrust();
}
// Start is called before the first frame update
private void Start()
{
rb = gameObject.GetComponent<Rigidbody>();
// ground detection constants
//playerHeight = (transform.localScale.y / 2f);
//Vector3 boxDim = transform.localScale;
//boxDim = new Vector3(boxDim.x - 0.5f, boxDim.y + 0.5f, boxDim.z - 0.5f);
maxSpeed = maxWalkSpeed;
airControl = defaultAirControl;
grappleHook = gameObject.GetComponent<GrappleHook>();
jetPack = gameObject.GetComponent<JetPack>();
playerStats = gameObject.GetComponent<PlayerStats>();
prevFrameSpeed = 0f;
}
// Update is called once per frame
private void Update()
{
var grounded = isGrounded();
// coyote time manager
if (grounded)
coyoteTimeCounter = coyoteTime;
else
coyoteTimeCounter -= Time.deltaTime;
// jump buffer manager
if (Input.GetButtonDown("Jump") )
jumpBufferCounter = jumpBuffer;
else
jumpBufferCounter -= Time.deltaTime;
//Debug.Log("Coyote: " + coyoteTimeCounter + ". Buffer: " + jumpBufferCounter);
// if jump key is pressed
if (coyoteTimeCounter > 0f && jumpBufferCounter > 0f)
{
Debug.Log("jump");
// apply an upward force to the player
rb.AddForce(new Vector3(0f, jumpForce, 0f));
coyoteTimeCounter = 0f;
jumpBufferCounter = 0f;
}
// change current max speed depending on sprinting or not
if (Input.GetKey(KeyCode.LeftShift) && grounded )
maxSpeed = maxRunSpeed;
else
maxSpeed = maxWalkSpeed;
}
private void FixedUpdate()
{
// get the input values for player movement
var movement = GetMoveInputs();
// calculate the velocity change of the player based on input
movement = movement.normalized * walkingForce;
// scale movement force if not on ground
if (!isGrounded()) movement *= airControl;
var relativeMove = transform.right * movement.x + transform.forward * movement.z;
var flatCurVelocity = Vector3.ProjectOnPlane(rb.velocity, transform.up);
// calculate the velocity the player would have when adding input velocity to it
var nextVelocity = flatCurVelocity + relativeMove * Time.deltaTime;
// check if the player's next velocity has a magnitude above walking speed
if (nextVelocity.magnitude > maxSpeed)
{
// if the player is currently moving below their maxSpeed and trying to accelerate up to it
if (flatCurVelocity.magnitude < maxSpeed)
// scale the player's next velocity to be equal to their maxSpeed
nextVelocity = nextVelocity.normalized * maxSpeed;
else
// else, scale the player's next velocity to equal their current speed
nextVelocity = nextVelocity.normalized * flatCurVelocity.magnitude;
}
// set the player's current velocity to their next velocity in the xz-plane
rb.velocity = new Vector3(nextVelocity.x, rb.velocity.y, nextVelocity.z);
// apply the force of a potential grapple hook to the player
rb.AddForce(grappleHook.PullForce(transform.position));
// apply the force of a potential jetpack to the player
rb.AddForce(jetPack.ThrustForce());
// apply the force of gravity to the player
rb.AddForce(gravity, ForceMode.Acceleration);
// calculate the change in player speed this frame
var deltaSpeed = Mathf.Abs(rb.velocity.magnitude - prevFrameSpeed);
// apply force damage to player depending on change in speed
if (deltaSpeed > speedDamageThreshold)
//Debug.Log(deltaSpeed - speedDamageThreshold);
playerStats.ChangeHealth(-speedToDamage * (deltaSpeed - speedDamageThreshold));
// update speed record for next frame
prevFrameSpeed = rb.velocity.magnitude;
//Debug.Log(isGrounded());
}
private void OnTriggerEnter(Collider other)
{
var tp = other.gameObject.GetComponent<TraversalProperties>();
if (tp != null && tp.lethalToEnter) playerStats.Respawn();
}
public Vector3 GetMoveInputs()
{
var xzMove = Vector3.zero;
if (Input.GetKey(KeyCode.W)) xzMove.z += 1f;
if (Input.GetKey(KeyCode.S)) xzMove.z += -1f;
if (Input.GetKey(KeyCode.D)) xzMove.x += 1f;
if (Input.GetKey(KeyCode.A)) xzMove.x += -1f;
return xzMove;
}
public bool isGrounded()
{
// Raycast using ray
//return Physics.Raycast(transform.position, -Vector3.up, playerHeight + 0.1f);
// Raycast using box
//Vector3 boxCenter = transform.position - new Vector3(0f, playerHeight, 0f);
//return Physics.CheckBox(boxCenter, boxDim);
// Raycast using box hardcoded
var boxCenter = transform.position - new Vector3(0f, 0.5f, 0f);
return Physics.CheckBox(boxCenter, new Vector3(0.25f, 0.52f, 0.25f));
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6371500714cc7409c92e2a14cced0fca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: