Hey guys,
I made a base building game where you place your buildings on a grid.
Now I created an AI that also builds a base and I want it to face the player with it's base.
I can't just rotate the object, that leads to a lot of problems in my code.
How do I calculate the new position in a grid when immitating rotation?
For 180° it works like: newX = gridSizeX - oldX and newY = gridSizeY - oldY. In the example image the grid the red cube is 0° and the blue cube is the new position after rotating by 90°, how do I calculate the new position?
In some cases switching x and y works, in some cases I can leave x and just change y, it is very confusing.
Please help!
[1]: /storage/temp/160595-grid-example.png
,Hey guys,
I built a base building game using a grid to place objects on it.
Now I made an AI to build objects as well. I want the AI to face the player with its castle.
I can't just rotate the grids object, that leads to a ton of problems in my code.
Is there a way to change the objects inside a grid to immitate rotating?
In the example below the red cube is rotation 0°, the blue cube is rotation 90°.
How do I calculate the new position?
With rotating 180° this is easy:
newX = gridsize - oldX /
newY = gridsize - oldY
But I can't get 90° and 270° to working.
Sometimes leaving x and just changing y works, it's very confusing.
Please help.
↧