This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a basic dummy version of a Stability Augmentation System. There's a bunch of technical | |
// terms for this, but I'm not a control systems engineer so feel free to correct me. I found a | |
// really awesome document (video?) somewhere that explained all this stuff but it was a while ago | |
// but I forgot where I saw it. | |
// This is meant to be set up per channel. It's serializable so you can change | |
// the authority and power of it per channel in the Inspector. | |
[System.Serializable] | |
public class SASChannel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
/// <summary> | |
/// Creates a very simple linear graph that can be sampled along arbitrary points. Clamps to | |
/// the nearest value when sampled out of range. This class assumes that all points given are | |
/// ALREADY SORTED from smallest to largest in the X axis. There is NO automatic sorting. | |
/// </summary> | |
public class InterpolatedCurve | |
{ | |
public List<(float, float)> Points = new List<(float, float)>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
// Thanks to Rory Driscoll | |
// http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/ | |
public static class SmoothDamp | |
{ | |
/// <summary> | |
/// Creates dampened motion between a and b that is framerate independent. | |
/// </summary> | |
/// <param name="from">Initial parameter</param> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is an example of how to use the new input system in a way that I think is actually | |
// usable for a production game, and not just rapid prototyping. This is much more stable, | |
// and because it uses the C# class version of the new Input System it will fail to compile | |
// if something changes in the input asset, which is a VERY GOOD THING. | |
using UnityEngine; | |
public class CameraInput | |
{ | |
public float Pitch = 0f; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==================================================================================================== | |
// In my codebase, all ships have their own instance of this that they use to apply physics with. | |
// I'm using a struct mostly because I want to maintain copy semantics. | |
// ==================================================================================================== | |
public struct FlightInput | |
{ | |
public float Pitch; | |
public float Yaw; | |
public float Roll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PixelPerfectTrail : MonoBehaviour | |
{ | |
[SerializeField] private TrailRenderer trail = null; | |
[Tooltip("How small the trail width is allowed to get in pixels.")] | |
public float MinimumPixelSize = 1.5f; | |
private float startSize = 1f; | |
private void Awake() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Computes a point for a gun to aim at in order to hit a target using linear prediction. | |
/// Assumes a bullet with no gravity or drag. I.e. A bullet that maintains a constant | |
/// velocity after it's been fired. | |
/// </summary> | |
public static Vector3 ComputeGunLead(Vector3 targetPos, Vector3 targetVel, Vector3 ownPos, Vector3 ownVel, float muzzleVelocity) | |
{ | |
// Extremely low muzzle velocities are unlikely to ever hit. This also prevents a | |
// possible division by zero if the muzzle velocity is zero for whatever reason. | |
if (muzzleVelocity < 1f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Threading; | |
using Cysharp.Threading.Tasks; | |
using TMPro; | |
public static class TextMeshProExtensions | |
{ | |
private static Dictionary<TextMeshProUGUI, CancellationTokenSource> textToCancel = new Dictionary<TextMeshProUGUI, CancellationTokenSource>(); |
NewerOlder