- Home /
Question by
TheForsaken95 · Oct 15, 2016 at 07:39 PM ·
rotationpathfindingcharacter movementfor-loop
Need help rotating multiple paths on an axis
I am building an RTS game similar to Age of Empires 3, and I've hit a wall. I have a for loop that sets the path of all your selected units, and then spaces them out evenly into a grid formation. (Here is the code)
int maxColumns = 5;
float spacing = 1.5f;
int height = 0;
int width = 0;
int objectCount = selectedObjects.Count;
for (int i = 0; i < selectedObjects.Count; i++) {
Vector3 location = hit.point + new Vector3 (width * spacing, 0, height * spacing);
selectedObjects [i].GetComponent<NavMeshAgent> ().SetDestination (location);
width++;
if (width == maxColumns) {
width = 0;
height++;
}
}
Now this code will move my units into a grid at the spot that you commanded them to go to on the map, like this.
Now this is great, however I need these paths to move in a square formation that isn't always aligned straight up and down, but rather rotates based on what direction they are walking towards. (Like this)
Any help on this would be appreciated!
example.png
(411.5 kB)
example2.png
(18.2 kB)
Comment