Ship.Update reads Turn and feeds the rotation thrusters and aether drives; it no longer reads the look direction or snaps Direction toward it. Steering.Toward is the one law from heading to demand (a heading astern now turns at full demand). HelmInput owns the face-the-aim state. Accelerate, Combat and MoveTo write Turn through Steering.Toward. Entity.LookDirection is renamed Aim in the simulation, the Unity readers and the tests. Unity player input follows in the next commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
|
|
using GameCult.Caching;
|
|
using System;
|
|
using CultMath;
|
|
using static CultMath.math;
|
|
using float2 = CultMath.float2;
|
|
|
|
public abstract class MoveToState : BaseState
|
|
{
|
|
private VelocityLimit _velocityLimit;
|
|
protected abstract float2 TargetPosition { get; }
|
|
public float Distance { get; private set; }
|
|
|
|
protected MoveToState(Agent agent) : base(agent)
|
|
{
|
|
}
|
|
|
|
public override void Update(float delta)
|
|
{
|
|
var diff = TargetPosition - _agent.Ship.Position.xz;
|
|
var dir = normalize(diff);
|
|
Distance = length(diff);
|
|
|
|
// We want to go top speed in the direction of our target
|
|
var desiredVelocity = dir * _agent.TopSpeed;
|
|
_agent.Ship.Aim = float3(dir.x, 0, dir.y);
|
|
_agent.Ship.Turn = Steering.Toward(_agent.Ship, dir);
|
|
_agent.Accelerate(desiredVelocity);
|
|
}
|
|
}
|
|
|
|
public class MoveToOrbitState : MoveToState
|
|
{
|
|
public CultRecordKey Orbit { get; set; }
|
|
public MoveToOrbitState(Agent agent) : base(agent) { }
|
|
|
|
protected override float2 TargetPosition => _agent.Ship.Zone.GetOrbitPosition(Orbit);
|
|
}
|