0

Im making a game where we made a tilemap, the tilemap is a list with tile objects. Tile objects have a position. We want to be able to remove these tiles and asking around i go told to use

tiles.RemoveAll(item => item.position == new Vector2(MathF.Round(playerPosition.X), MathF.Round(playerPosition.Y)))

How ever, this does not remove any of the tile objects even if the vectors match.

madreflection
  • 4,744
  • 3
  • 19
  • 29
Viktor
  • 1
  • 1
  • 1
  • 2
    It is likely that the vectors do not actually match, due to floating point precision. Try checking for an approximate position instead. – hijinxbassist Jan 06 '22 at 20:26
  • 1
    Sometimes it's helpful to move inline calculations like `MathF.Round(playerPosition.X)` to a separate line (e.g., `var x = MathF.Round(playerPosition.X);`) and log it or inspect it in a debugger. It may not be what you expected. – Tech Inquisitor Jan 06 '22 at 20:29

0 Answers0