This may be a simple question, but I haven’t found anything to solve this:
How can I achieve the avoidance of units based on their colliders? Currently, they’re all moving to the same spot.
Example: I have 3 Units selected ans sent them tp one point: they move all to this point and are stuck within each other
This is my movement script for (multiple) units so far:
private void MakeMove(Vector3 dir)
{
inCover = false;
transform.LookAt(dir);
float scaledSpeed = 1 / moveSpeed;
transform.position = Vector3.Lerp(transform.position, dir, scaledSpeed);
if (transform.position == destination) moving = false;
CalculateBounds();
}
This is used for walking on the given path to the next checkpoint.
The code below is used to send the selected units to the desired location:
foreach (WorldObject worldObject in player.SelectedObjects)
{
if (worldObject.GetComponent<Unit>() != null)
{
worldObject.GetComponent<Unit>().MouseClick(hitObject, hitPoint, player);
}
else
{
worldObject.MouseClick(hitObject, hitPoint, player);
}
}
MouseClick returns the destination based on the hit.point coordinates and starts the path:
seeker.StartPath(transform.position, _destination, OnPathComplete);
My attempt was to hard-code the distances, so e.g send one unit to the clickpoint and all other units get a random point close to this, but this doesnt work correctly and also has problems, if there are already obstacles at/near the given position