Aetheria/Assets/Scripts/ServerShared/Agents/States/MoveTo.cs
soul 9a2a9390e1 Command seam, agents: one PilotCommand per entity, applied once per step by PilotApplier in Zone.Update
Agent, Flight, Combat, MoveTo and Follow write only Ship.Command. Entities
with no agent apply first, then each agent applies right after it decides.
A pilot reads its own pending designation and aim item back from its command;
FireControl gains Refuses/AgentFires/HitProbability overloads that take them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 00:32:11 +02:00

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.Command.Aim = float3(dir.x, 0, dir.y);
_agent.Ship.Command.Turn = TurnCommand.Toward(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);
}