LibGDX movement faster on the y axis when multiplying by delta

Hi all, simply issue I believe. Think I might of missed something easy D:

I’m moving my entities tile by tile until they reach the waypoint. For some odd reason, multiplying the movement code by delta causes the entities to move faster on the y axis. If I remove the delta time, the movement is the same. I’ve included the movement code below, but I’m worried it could be something else;


Tile nextTile = level.getCompletedPathListTile(entity.getTileIndex()); // Get the tile to move to

Vector2 direction = new Vector2(nextTile.getX() * Level.TILE_WIDTH - entity.getxPos(), nextTile.getY() * Level.TILE_HEIGHT - entity.getyPos());
direction.nor();
			// Speed is currently set at 60
entity.setxPos((int) (entity.getxPos() + direction.x * 60 * Gdx.graphics.getDeltaTime()));
entity.setyPos((int) (entity.getyPos() + direction.y * 60 * Gdx.graphics.getDeltaTime()));


Okay so I made a stupid mistake. I’ve had a similar issue to this before and Jesse actually helped me fix it.

First issue seems to (maybe :persecutioncomplex:) be that casting floats to int’s didn’t really work well.
Second and the biggest issue. I’m checking if the character reaches the next tile, which is the big mistake. Instead of the above code, I did the following and it now works!


	
for(Entity entity : entityList){
			
   if(!(entity.getTileIndex() >= level.getCompletedPathList().size())){
       Tile nextTile = level.getCompletedPathListTile(entity.getTileIndex());
			
       Vector2 direction = new Vector2(nextTile.getX() * Level.TILE_WIDTH - entity.getxPos(), nextTile.getY() * Level.TILE_HEIGHT - entity.getyPos());
       direction.nor();
			
       entity.setxPos(entity.getxPos() + direction.x * Entity.totalDistanceToTravel);
       entity.setyPos(entity.getyPos() + direction.y * Entity.totalDistanceToTravel);
				
       entity.setTotalDistance(entity.getTotalDistance() + Entity.totalDistanceToTravel);
				
       if(entity.getTotalDistance() >= 32){
	    entity.setIndex(entity.getTileIndex() +1);
	    entity.setTotalDistance(0);
     }
}

To sum this code up. I get a vector that points to the next tile and normalise it. I then add it to the players direction, multiply that by the totalDistanceToTravelThisUpdate (60 * delta). I then add the distanceToTravelThisUpdate to the totalDistance, which is stored inside the entity class. If the entity’s distance is bigger or equal to the distance to the next tile then we reset the total distance and move to the next tile.

Big thank you to Jesse for this :slight_smile: :point: