||Topic was automatically imported from the old Question2Answer platform.
||Published before Godot 3 was released.
I was comparing two Vector2 in this way:
var pos = $"../TileMap".world_to_map(posPlayer)
for i in range(0, sizeMap, 16):
if pos >= Vector2(i, i) && pos <= Vector2(i + 16, i + 16):
if pos.x > pos.y:
posChunk = Vector2(i, i) - Vector2(32, 48)
posChunk= Vector2(i, i) - Vector2(16, 16)
But this exception of when x is greater than y, is not working very well, I’m trying to generate the map around the player, and I thought about it, to find the chunk in which the player is and then generate a certain amount of map , in the case of 64x64 in the position of the player - 16, so the player being in (16, 16) would instantiate 64x64 cells from the position (0, 0), which would leave the player surrounded by map, but due to some cases where x is greater than y would not work. I read a response in git saying to use the comparison of Rect2, however I do not know how to compare two Rect2 for my situation, would it be the best way, or am I thinking wrong?
Likely something like this:
if(Rect2(Vector2(i, i), Vector2(16, 16)).has_point(pos)):
I think that’s not it, I do not want to check if they’re overlapping:
bool has_point ( Vector2 point )
Return true if the Rect2 contains a point.
I want to find the chunk the player is in. This would not work.
PerduGames | 2017-09-09 14:04
Have you tried it?
Because your posted logic indicates you want to find out if a point is inside a rectangle. This is the same thing. You’re creating a rectangle using the tile start position and dimensions, and testing to see if the player position is inside of it.
Though I am having a hard time understanding your question.
avencherus | 2017-09-09 14:30
I understood, I think it works, it would not be inside the tile, but then just put the bigger square and it will work, I’ll try.
PerduGames | 2017-09-09 14:35
It seems that it worked correctly, which was confusing me and now I realized, it did not paint exactly in the middle, because it was instanciando the player at the ends of the map, and it ends up not generating, therefore there is no more map, type in a map of 128x128, and the player playing in (120,120) or (0, 0), there is no map for him to paint, so he was not in the center, I did not pay attention, thank you. I will only deal with this matter of extremes now and I think it will be all right.
PerduGames | 2017-09-09 14:45