1
\$\begingroup\$

In the below image, the character texture is properly sync to body even moving on free space.

enter image description here

In the below image, the character is moving downward. But the texture got a span or not sync properly, when there is an obstacle or a wall.

enter image description here

The systems I've use for the data logic (ECS)

class MovementSystem extends IteratingSystem {

      @Override
      public void processEntity(Entity entity, float deltaTime) {
            PositionComponent position = ...
            VelocityComponent velocity = ...

            position.x = velocity.x * deltaTime;
            position.y = velocity.y * deltaTime;
      }

}

class PhysicsSystem extends IteratingSystems {

      @Override
      public void processEntity(Entity entity, float deltaTime) {
           PositionComponent position ...
           BodyComponent body...

           position.set(body.getPosition());
      }

}


class RenderingSystem extends IteratingSystem {

      @Override
      public void processEntity(Entity entity, float deltaTime) {
           PositionComponent position ...
           SpriteComponent sprite ...

           batch.draw(sprite.texture, position...);
      }

}

I know the problem is in the part of MovementSystem positioning, the position is still incremented by velocity multiplied by delta time even the body is not moving while pressing move button.

\$\endgroup\$
1
\$\begingroup\$

Some years ago, Blizzard had an April fool's joke about World of Warcraft: the Ogre character (two-headed), could be played by two players. This was hilarious, because it's a non-sense.

You're doing the same thing here: you have two different systems that control the same component.

An entity's position should be controlled either by the PhysicsSystem or by the MovementSystem, not by both.

In either case, you'll need to create a controller component. In the case of the Physics system, the controller will apply forces desired by the user. In the case of the Movement system, the movement will be decided by other means, i.e. you'll have to manage the velocity and other parameters by yourself (like what you're doing now).

If the velocity is needed by some other systems (for instance the 'rendering' system could use it to render a trail of some kind), you'll have to make sure that this is also updated by the Physics system.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.