How do i calculate a new position for my units with angle based on the difference between old position and new position? IMAGE PROVIDED
Hello, I've been trying to implement an RTS style unit controller, in which multiple units form a formation as seen in figure 1, in the picture below. However i've been struggling to implement the feature where the units also rotate towards the new position issued, as seen in the figure 2. Does anyone have any clues how to tackle this problem? I know that i need to apply angle to the new vectors that are being created based on the angle difference between two points, however i do not know how to put this into code. Does anyone have a clue how to solve this problem? Here is the code:
List<Vector3> calculatePositionList(Vector3 newLocation, Vector3 oldLocation)
{
int counter = 0;
bool flag = true;
List<Vector3> PositionList = new List<Vector3>();
foreach (GameObject unit in _units)
{
PositionList.Add(newLocation + new Vector3((float)(counter * 1.1), 0, 0));//TODO angle
if (flag)
{
if (counter < 0)
{
counter = -counter;
}
counter++;
flag = false;
}
else
{
counter = -counter;
flag = true;
}
Debug.Log(counter);
}
return PositionList;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613041105im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Determining if my target is standing upright 4 Answers
calculate different angles in 2d 1 Answer
How to get local angle of travel 0 Answers
Instantiating Projectiles not working at certain directions?? 2 Answers
Unit Circle Coordinates 0 Answers