Улучшения в физике системы libgdx - PullRequest
1 голос
/ 21 октября 2019

хочу написать свою физику в libgdx с помощью ashley ECS framework. Итак, я создал физическую систему, но ее поведение не хорошо с renderind. Я подумал, что он должен быть независимым от фреймов и добавил следующий код, но мне не нравится поведение в этом случае. Вот код:

public class PhysicsSystem extends IteratingSystem {
    private float accumulator = 0;
    private static final float TIME_STEP = 1 / 120f;


    private ComponentMapper<PhysicsComponent> pcm = ComponentMapper.getFor(PhysicsComponent.class);

    public PhysicsSystem(Family family) {
        super(family);
    }

    @Override
    public void update(float deltaTime) {

        float frameTime = Math.min(deltaTime, 0.25f);
        accumulator += frameTime;

        while (accumulator >= TIME_STEP) {
            accumulator -= TIME_STEP;
            super.update(TIME_STEP);
        }
    }

    @Override
    protected void processEntity(Entity entity, float deltaTime) {
        PhysicsComponent physicsComponent = pcm.get(entity);

        physicsComponent.applyForce(0, -9.8f * deltaTime);

        physicsComponent.position.add(physicsComponent.velocity.x * deltaTime, 
physicsComponent.velocity.y * deltaTime);

     }
}

Так есть ли способы улучшить мою физику? Любой совет может помочь.

...