- Home /
I asked for help too soon it seems. I've figured it out now and no longer need help! Thanks anyway.
Formation of Units doesn't account for rotation
Hello,
I am having issues with a formation script I have been mucking around with. Essentially, I am looking to make a basic formation system similar to the Mount & Blade games, where the units move into position in a grid behind the player or at a specific point and this grid can be dynamically adjusted (number of rows, number of units in the formation, etc.)
Most all of the script is working as I intend but when the primary point rotates, the units don't rotate around the back of the object.
I have attached a picture to better explain
The following code is in Update and builds the grip for the units to move to. I believe the issue is with the X and Z positions. I'd need to have them adjust to reflect the rotation of the RallyPoint but I cannot for the life of me think of how I'd do that. Sorry if the answer is obvious
Vector3 formationStartPosition = rallyPoint.transform.localPosition - rallyPoint.transform.forward;
for (int i = 0; i < units.Length; i++)
{
for (int y = 0; y < rows; y++)
{
if (i % 2 == 0)
{
positions[i] = new Vector3(formationStartPosition.x + (seperation * i), formationStartPosition.y, formationStartPosition.z);
}
else
{
positions[i] = new Vector3(formationStartPosition.x + (seperation * i), formationStartPosition.y, formationStartPosition.z - seperation);
}
}
}
Second Image of the script running currently. Capsule is the RallyPoint and Squares are the Units. Can someone offer any advice on what I could do? Thanks!
Follow this Question
Related Questions
Rotate player (rigidbody) towards his movement 2 Answers
Player not facing the mouse correctly 1 Answer
Rotating wrong 0 Answers