I am currently working on the prototype of a city building game. Sadly I just run into a problem which I can’t solve due to lack of knowledge in vector operations. The game has a grid of 20x20 tiles. When I build something on a tile, the coordinates now occupied by that building get stored into an “OccupiedPositions” array. Now I am trying to build roads: conceptually, I must place a Flag A where I want the road to start and a Flag B where I want the road to finish. How can I find the coordinates between the two points and recalculating the path for avoiding the “OccupiedPositions” stored coordinates? I know it is not an easy task but I would really appreciate your help. Thank you in advance!
That is just adding vectors. Without your code i cannot give any real solution. You need solve it yourself and learn. If you do not get practice now, next problem will be even harder. Just keep doing it at some point you get past all those small troubles.
Thanks for the thought but I did not want a solution for my specific code (which is fairly simple anyway: I have got a starting point and an end point and must store every coordinates distant 20 on X axis or Y axis avoiding collisions with other objects already stored). What I would have done is an A* pathfinding , but I don’t have enough time for this, unfortunately. I opted for a simpler solution: it is possible to build road only if the end point is on the y axis or the x axis of the starting one. With a loop I check for collisions and, if there aren’t any, save every coordinates and spawn the road. Just wanted to know if someone had a better solution more similar to the idea I have first described but I guess I am in the wrong place for that, my apologies.