ChunkLoader don't load Chunk correctly when Actor is in a negative position
sgervais333 opened this issue · comments
When the actor is in a negative postition, it does not work.
The solution is to change the code in 'chunk_loader_2d' and 'chunk_loader_3d' to put a cast float() in one of the variable:
func _get_actors_position() -> Vector2i:
# getting actors positions
var actor_position := Vector2i.ZERO
if actor != null: actor_position = actor.global_position.floor()
var tile_position: Vector2i = actor_position / generator.tile_size
var chunk_position := Vector2i(
floori(float(tile_position.x) / generator.chunk_size.x),
floori(float(tile_position.y) / generator.chunk_size.y)
)
return chunk_position
func _get_actors_position() -> Vector3i:
# getting actors positions
var actor_position := Vector3i.ZERO
if actor != null: actor_position = actor.global_position.round()
var tile_position: Vector3i = actor_position / generator.tile_size
var chunk_position := Vector3i(
roundi(float(tile_position.x) / generator.chunk_size.x),
roundi(float(tile_position.y) / generator.chunk_size.y),
roundi(float(tile_position.z) / generator.chunk_size.z)
)
return chunk_position
Thank you so much! Was wondering how to fix that. Could you make a PR?