KavTest/KavTest/Engines/MoveAlongCurve3DEngine.cs

30 lines
1.0 KiB
C#

using Encompass;
using KavTest.Components;
using KavTest.Messages;
namespace KavTest.Engines
{
[Sends(typeof(TranslationMessage))]
[Writes(typeof(MoveAlongCurve3DComponent))]
[QueryWith(typeof(MoveAlongCurve3DComponent), typeof(Transform3DComponent))]
public class MoveAlongCurve3DEngine : Engine
{
public override void Update(double dt)
{
foreach (var entity in TrackedEntities)
{
ref readonly var movealongCurveComponent = ref GetComponent<MoveAlongCurve3DComponent>(entity);
ref readonly var transformComponent = ref GetComponent<Transform3DComponent>(entity);
var newCurve = new MoveAlongCurve3DComponent(
movealongCurveComponent.Curve,
movealongCurveComponent.Time + (float)dt
);
SendMessage(new TranslationMessage(entity, newCurve.Position - transformComponent.Transform.Position));
SetComponent(entity, newCurve);
}
}
}
}