Aetheria/Assets/Scripts/ServerShared/Agents/AgentBehavior.cs
Reinier Vens c4be204cd0 First Flight
Added MPL license headers
SectorRenderer renders entities in sector, manages particle systems for ship thrusters
Thrusters apply torque based on orientation and position relative to ship center of mass
GameManager controls the player ship's thrusters
Player can dock with station if they are near
2020-12-22 03:13:43 +00:00

34 lines
1.4 KiB
C#

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using static Unity.Mathematics.math;
public abstract class AgentBehavior
{
public abstract void Update(float delta);
protected float ThrustInput(float2 deltaV) =>
saturate( // Input must be normalized
pow( // Apply specificity as exponent to dot product to control how specific the direction needs to be
saturate( // Discard negative dot product (we're facing away from desired direction)
dot(normalize(Entity.Direction), normalize(deltaV))), // Cosine of angle between direction and deltaV
ControllerData.ThrustSpecificity)
* length(deltaV) * ControllerData.ThrustSensitivity);
protected float TurningInput(float2 deltaV) => clamp(-Entity.Direction.AngleDiff(deltaV) * ControllerData.TurningSensitivity, -1, 1);
protected ControllerData ControllerData;
protected ItemManager Context;
protected Entity Entity;
public AgentBehavior(ItemManager context, Entity entity, ControllerData controllerData)
{
Context = context;
Entity = entity;
ControllerData = controllerData;
}
}