Aetheria/Assets/Scripts/ServerShared/Behaviors/VelocityLimit.cs
hyperion51 b589a6422c Ship Locomotion & Tech Tree Panel
Ship locomotion now accounts for tangential velocity, slows down properly with terminal phase separated into velocity matching behavior
Tech tree properties panel visualizes parents and children correctly
2020-04-25 00:01:13 +01:00

46 lines
No EOL
1.2 KiB
C#

using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class VelocityLimitData : IBehaviorData
{
[InspectableField, JsonProperty("topSpeed"), Key(0)]
public PerformanceStat TopSpeed = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new VelocityLimit(context, this, entity, item);
}
}
public class VelocityLimit : IBehavior
{
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IBehaviorData Data => _data;
private VelocityLimitData _data;
public VelocityLimit(GameContext context, VelocityLimitData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public void Initialize()
{
}
public void Update(float delta)
{
var limit = Context.Evaluate(_data.TopSpeed, Item, Entity);
if (length(Entity.Velocity) > limit)
Entity.Velocity = normalize(Entity.Velocity) * limit;
}
}