Wormholes
This commit is contained in:
parent
4b10923448
commit
adfb200a91
38 changed files with 1102 additions and 59 deletions
|
|
@ -89,7 +89,7 @@ public abstract class PersistentBehaviorData
|
|||
Union(6, typeof(ReflectorData)),
|
||||
Union(7, typeof(ShieldData)),
|
||||
Union(8, typeof(ThrusterData)),
|
||||
// Union(9, typeof(TurningData)),
|
||||
Union(9, typeof(WearData)),
|
||||
Union(10, typeof(VelocityConversionData)),
|
||||
Union(11, typeof(VelocityLimitData)),
|
||||
Union(12, typeof(FactoryData)),
|
||||
|
|
@ -113,7 +113,7 @@ public abstract class PersistentBehaviorData
|
|||
// Union(30, typeof(HaulingControllerData)),
|
||||
Union(31, typeof(CapacitorData)),
|
||||
Union(32, typeof(CockpitData)),
|
||||
Union(33, typeof(HeatsinkData)),
|
||||
Union(33, typeof(HeatStorageData)),
|
||||
Union(34, typeof(TurretControllerData)),
|
||||
Union(35, typeof(InstantWeaponData)),
|
||||
Union(36, typeof(ConstantWeaponData)),
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@ using Unity.Mathematics;
|
|||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class HeatsinkData : BehaviorData
|
||||
public class HeatStorageData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new Heatsink(context, this, entity, item);
|
||||
return new HeatStorage(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Heatsink : IBehavior
|
||||
public class HeatStorage : IBehavior
|
||||
{
|
||||
private HeatsinkData _data;
|
||||
private HeatStorageData _data;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
|
|
@ -27,7 +27,7 @@ public class Heatsink : IBehavior
|
|||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public Heatsink(ItemManager context, HeatsinkData data, Entity entity, EquippedItem item)
|
||||
public HeatStorage(ItemManager context, HeatStorageData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
|
|
@ -73,6 +73,6 @@ public class Thruster : IAnalogBehavior
|
|||
var vis = _input * Context.Evaluate(_data.Visibility, Item);
|
||||
if(!Entity.VisibilitySources.ContainsKey(this) || vis > Entity.VisibilitySources[this])
|
||||
Entity.VisibilitySources[this] = vis;
|
||||
return true;
|
||||
return _input > .01f;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ using System.Linq;
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Union(0, typeof(InstantWeaponData)),
|
||||
Union(1, typeof(LauncherData)),
|
||||
|
|
@ -123,7 +124,10 @@ public abstract class Weapon : IActivatedBehavior
|
|||
Visibility = Context.Evaluate(_data.Visibility, Item);
|
||||
Spread = Context.Evaluate(_data.Spread, Item);
|
||||
Velocity = Context.Evaluate(_data.Velocity, Item);
|
||||
Wear = Context.Evaluate(_itemData.WearDamage, Item);
|
||||
Wear = (1 - pow(_itemData.Performance(Item.Temperature),
|
||||
(1 - pow(Item.EquippableItem.Quality, Context.GameplaySettings.QualityWearExponent)) *
|
||||
Context.GameplaySettings.ThermalWearExponent)
|
||||
) * _itemData.Durability;
|
||||
}
|
||||
|
||||
public virtual bool Execute(float delta)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ using static Unity.Mathematics.math;
|
|||
public class WearData : BehaviorData
|
||||
{
|
||||
[TemperatureInspectable, JsonProperty("perSecond"), Key(1)]
|
||||
public bool PerSecond;
|
||||
public bool PerSecond = true;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
|
|
@ -42,7 +42,10 @@ public class Wear : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
var wear = Context.Evaluate(_itemData.WearDamage, Item);
|
||||
var wear = (1 - pow(_itemData.Performance(Item.Temperature),
|
||||
(1 - pow(Item.EquippableItem.Quality, Context.GameplaySettings.QualityWearExponent)) *
|
||||
Context.GameplaySettings.ThermalWearExponent)
|
||||
) * _itemData.Durability / _itemData.ThermalResilience;
|
||||
if (_data.PerSecond) wear *= delta;
|
||||
Item.EquippableItem.Durability -= wear;
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -297,8 +297,8 @@ public abstract class EquippableItemData : CraftedItemData
|
|||
[InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(17)]
|
||||
public float4[] HeatPerformanceCurve;
|
||||
|
||||
[InspectableField, JsonProperty("wearDamage"), Key(18)]
|
||||
public PerformanceStat WearDamage = new PerformanceStat();
|
||||
[InspectableField, JsonProperty("resilience"), Key(18)]
|
||||
public float ThermalResilience = 1;
|
||||
|
||||
[IgnoreMember]
|
||||
public abstract HardpointType HardpointType { get; }
|
||||
|
|
|
|||
|
|
@ -88,6 +88,13 @@ public class ZoneGenerationSettings
|
|||
[Serializable, MessagePackObject(keyAsPropertyName: true), JsonObject]
|
||||
public class GameplaySettings
|
||||
{
|
||||
public float WormholeDepth = 1000;
|
||||
public float WormholeExitVelocity = 20;
|
||||
public float WormholeExitRadius = 50;
|
||||
public float WormholeAnimationDuration = 4;
|
||||
public float WormholeExitCurveStart = .8f;
|
||||
public float ThermalWearExponent = .01f;
|
||||
public float QualityWearExponent = 2;
|
||||
public int TriggerGroupCount = 6;
|
||||
public float WarpDistance = 25;
|
||||
public float DockingDistance = 25;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,15 @@ public class Ship : Entity
|
|||
private HashSet<Thruster> _leftThrusters;
|
||||
private HashSet<Thruster> _clockwiseThrusters;
|
||||
private HashSet<Thruster> _counterClockwiseThrusters;
|
||||
|
||||
|
||||
private bool _exitingWormhole = false;
|
||||
private bool _enteringWormhole = false;
|
||||
private float _wormholeAnimationProgress;
|
||||
private float2 _wormholeEntryPosition;
|
||||
private float2 _wormholeEntryDirection;
|
||||
private float2 _wormholePosition;
|
||||
private float2 _wormholeExitVelocity;
|
||||
|
||||
public float ForwardThrust { get; private set; }
|
||||
public float ReverseThrust { get; private set; }
|
||||
public float LeftStrafeThrust { get; private set; }
|
||||
|
|
@ -52,9 +60,30 @@ public class Ship : Entity
|
|||
var clockwise = dot(direction, Direction.Rotate(ItemRotation.Clockwise)) > 0;
|
||||
return angleDiff / ((clockwise ? ClockwiseTorque : CounterClockwiseTorque) / Mass);
|
||||
}
|
||||
|
||||
public event Action OnExitedWormhole;
|
||||
public event Action OnEnteredWormhole;
|
||||
|
||||
public quaternion Rotation { get; private set; }
|
||||
|
||||
public void ExitWormhole(float2 wormholePosition, float2 exitVelocity)
|
||||
{
|
||||
_exitingWormhole = true;
|
||||
_wormholeAnimationProgress = 0;
|
||||
_wormholePosition = wormholePosition;
|
||||
_wormholeExitVelocity = exitVelocity;
|
||||
Direction = normalize(exitVelocity);
|
||||
}
|
||||
|
||||
public void EnterWormhole(float2 wormholePosition)
|
||||
{
|
||||
_wormholeAnimationProgress = 0;
|
||||
_enteringWormhole = true;
|
||||
_wormholeEntryPosition = Position.xz;
|
||||
_wormholeEntryDirection = normalize(_wormholeEntryPosition-wormholePosition);
|
||||
_wormholePosition = wormholePosition;
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
base.Activate();
|
||||
|
|
@ -113,6 +142,8 @@ public class Ship : Entity
|
|||
ItemOnline.Subscribe(CheckForThruster);
|
||||
}
|
||||
|
||||
#region ThrustCalculation
|
||||
|
||||
private void RecalculateForwardThrust()
|
||||
{
|
||||
ForwardThrust = 0;
|
||||
|
|
@ -187,10 +218,11 @@ public class Ship : Entity
|
|||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void Update(float delta)
|
||||
{
|
||||
Position.xz += Velocity * delta;
|
||||
if (_active)
|
||||
if (_active && !_exitingWormhole)
|
||||
{
|
||||
foreach (var thruster in _allThrusters) thruster.Axis = 0;
|
||||
var rightThrusterTorqueCompensation = abs(RightStrafeTotalTorque) / RightStrafeTorqueThrusters.Length;
|
||||
|
|
@ -226,6 +258,9 @@ public class Ship : Entity
|
|||
foreach (var thruster in _clockwiseThrusters) thruster.Axis += deltaRot;
|
||||
foreach (var thruster in _counterClockwiseThrusters) thruster.Axis += -deltaRot;
|
||||
}
|
||||
|
||||
Position.xz += Velocity * delta;
|
||||
|
||||
var normal = Zone.GetNormal(Position.xz);
|
||||
var force = new float2(normal.x, normal.z);
|
||||
var forceMagnitude = lengthsq(force);
|
||||
|
|
@ -239,6 +274,69 @@ public class Ship : Entity
|
|||
Rotation = quaternion.LookRotation(forward, normal);
|
||||
|
||||
base.Update(delta);
|
||||
|
||||
if (_exitingWormhole)
|
||||
{
|
||||
_wormholeAnimationProgress += delta / ItemManager.GameplaySettings.WormholeAnimationDuration;
|
||||
if(_wormholeAnimationProgress < 1)
|
||||
{
|
||||
if (_wormholeAnimationProgress < ItemManager.GameplaySettings.WormholeExitCurveStart)
|
||||
{
|
||||
Position.xz = _wormholePosition;
|
||||
Rotation = quaternion.LookRotation(float3(0, 1, 0), float3(-Direction.x, 0, -Direction.y));
|
||||
}
|
||||
else
|
||||
{
|
||||
var exitLerp = _wormholeAnimationProgress - ItemManager.GameplaySettings.WormholeExitCurveStart /
|
||||
(1 - ItemManager.GameplaySettings.WormholeExitCurveStart);
|
||||
exitLerp *= exitLerp; // Square the interpolation variable to produce curve with zero slope at start
|
||||
Position.xz = _wormholePosition + normalize(_wormholeExitVelocity) * exitLerp * ItemManager.GameplaySettings.WormholeExitRadius;
|
||||
Rotation = quaternion.LookRotation(
|
||||
lerp(float3(0, 1, 0), forward, exitLerp),
|
||||
lerp(float3(-Direction.x, 0, -Direction.y), normal, exitLerp));
|
||||
}
|
||||
|
||||
Position.y = Position.y - lerp(ItemManager.GameplaySettings.WormholeDepth, 0, _wormholeAnimationProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
_exitingWormhole = false;
|
||||
OnExitedWormhole?.Invoke();
|
||||
OnExitedWormhole = null;
|
||||
Velocity = _wormholeExitVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
if (_enteringWormhole)
|
||||
{
|
||||
_wormholeAnimationProgress += delta / ItemManager.GameplaySettings.WormholeAnimationDuration;
|
||||
if(_wormholeAnimationProgress < 1)
|
||||
{
|
||||
if (_wormholeAnimationProgress < 1 - ItemManager.GameplaySettings.WormholeExitCurveStart)
|
||||
{
|
||||
var enterLerp = _wormholeAnimationProgress / (1 - ItemManager.GameplaySettings.WormholeExitCurveStart);
|
||||
enterLerp *= enterLerp; // Square the interpolation variable to produce curve with zero slope at vertical
|
||||
Position.xz = lerp(_wormholeEntryPosition, _wormholePosition, enterLerp);
|
||||
Rotation = quaternion.LookRotation(
|
||||
lerp(forward, float3(0, -1, 0), enterLerp),
|
||||
lerp(normal, float3(-_wormholeEntryDirection.x, 0, -_wormholeEntryDirection.y), enterLerp));
|
||||
}
|
||||
else
|
||||
{
|
||||
Position.xz = _wormholePosition;
|
||||
Rotation = quaternion.LookRotation(float3(0, -1, 0),
|
||||
float3(-_wormholeEntryDirection.x, 0, -_wormholeEntryDirection.y));
|
||||
}
|
||||
|
||||
Position.y = Position.y - lerp(0, ItemManager.GameplaySettings.WormholeDepth, _wormholeAnimationProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
_enteringWormhole = false;
|
||||
OnEnteredWormhole?.Invoke();
|
||||
OnEnteredWormhole = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
6
Assets/Scripts/ServerShared/Wormhole.cs
Normal file
6
Assets/Scripts/ServerShared/Wormhole.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
using Unity.Mathematics;
|
||||
|
||||
public class Wormhole
|
||||
{
|
||||
public float2 Position;
|
||||
}
|
||||
3
Assets/Scripts/ServerShared/Wormhole.cs.meta
Normal file
3
Assets/Scripts/ServerShared/Wormhole.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b5a943b5358a47a199ad5e7271c14032
|
||||
timeCreated: 1614907192
|
||||
Loading…
Reference in a new issue