I would like to move an Entity to a position that I want. But ECS changed a lot and I can't find working solutions for this. I have this basic code that suppose to move entitiy:
protected override void OnUpdate()
{
foreach ((LocalTransform localTransform, RefRO<Speed> speed, RefRW<TargetPosition> targetPosition) in SystemAPI.Query<LocalTransform, RefRO<Speed>, RefRW<TargetPosition>>())
{
Debug.LogFormat($"{nameof(MovingSystemBase)} - {nameof(OnUpdate)}");
float3 direction = math.normalize(targetPosition.ValueRW.targetPosition - localTransform.Position);
localTransform.Position += direction * SystemAPI.Time.DeltaTime * speed.ValueRO.moveSpeed;
//localTransform.Translate(direction * SystemAPI.Time.DeltaTime * speed.ValueRO.moveSpeed);
}
}
But I can not change localTransform.Position because it's in a struct.
(Foreach iteration variable 'localTransform' is immutable. Cannot modify struct member when accessed struct is not classified as a variable)
I tried the .Translate function but did not move my object. How can I achive this simple thing in latest ECS version?