Arch.Extended icon indicating copy to clipboard operation
Arch.Extended copied to clipboard

Using deltaTime in movement system?

Open Shadowblitz16 opened this issue 1 year ago • 1 comments

Your examples for BaseSystem doesn't include how to use deltatime

You can't just use deltaTime from the outer scope due to it not being valid in the lambda.

using Arch.Core;
using Arch.System;
using MineClone.Components;

namespace MineClone.Systems;

public class MovementSystem(World world) : BaseSystem<World, float>(world)
{
    private QueryDescription _description = new QueryDescription().WithAll<Position, Velocity>();
    public override void Update(in float delta)
    {
        base.Update(in delta);
        World.Query(in _description, (ref Position position, ref Velocity velocity) =>
        {
            position.Value += velocity.Value * delta; // cannot use in parameter delta
        });
    }
}

Shadowblitz16 avatar Oct 11 '24 21:10 Shadowblitz16

Copy it to a local

float localDeltaTime = deltaTime;

And use that instead. I know it's arch here and not you, but in here at all feels strange.

ClxS avatar Oct 14 '24 16:10 ClxS