gurkenlabs / litiengine

LITIENGINE 🕹 The pure 2D java game engine.
https://litiengine.com/
MIT License
725 stars 93 forks source link

Attempting to move creatures to the location they're already at #568

Closed nightm4re94 closed 1 year ago

nightm4re94 commented 1 year ago

Describe the bug When there is a gravity force applied to a Creature, its location will be set on every update despite the new location being identical to the old one when the Creature is colliding with something. This breaks the idle animations for the creature since the "last moved" tick is always the last update and the Creature never goes idle.

To Reproduce Steps to reproduce the behavior:

  1. Apply a force to a Creature, e.g. Gravity.
  2. Let the Creature collide with something while the Force is active
  3. The Creature can't keep moving, but the position is continuously set to the identical position in every update.
  4. The Creature's idle animation will never play because of this

Expected behavior

  1. Creature.setLocation() should not do anything if the new location is identical to the old one
    @Override
    public void setLocation(final Point2D position) {
    if (this.isDead() || position == null || position.equals(getLocation())) {
      return;
    }
    ...
    }
  2. PhysicsEngine.move() should not do anything if the target is identical to the entity's location
    public boolean move(final IMobileEntity entity, Point2D target) {
    if(target.equals(entity.getLocation())){
      return;
    }
    ...
    }
  3. See if there's a way to cancel the Gravity Force movement even earlier, before calling PhysicsEngine.move()