#Group of Game Objects error
1 messages · Page 1 of 1 (latest)
You need the concept of agent avoidance. Look if your A* provide such capacity. Unity Navmesh has the concept, you could try to use it.
are there red triangles visualizing the units destinations?
is it on purpose that the number of destinations appears to go from 4 to 3, suggesting that 2 share the same destination?
Yeah, I did not see that. You have 3 destination instead of 4.
Two triangles are placed on top of one another, so they arent deleted, just seemingly put in the same position.
sorry should've clarified that in my initial message, there are 4, each unit is individually assigned one, but for some reason they are set on top of each other.
okay that doesn't seem like an a* issue
the code that lays out the formation is buggy
how is it supposed to work? describe it in terms of the UX
Basically, the player holds down left click and drags to select a group of tanks within a selection box, and then right clicks to move the group of tanks together in a formation to the right clicked location. The player also has the ability to hold down right click and drag, which rotates the entire formation to face different directions based on the mouse position. Behind the scenes, the code also predicts the formation locations before setting the destination setters to them, so each tank is given the formation position that is closest to them.
Just an update to my own debugging also, i believe ive narrowed it down to something in the update method, such as when set formation occurs, or something to do with my CalculateMinDistance void, as the error seems to occur when the second tank is closer to the first position than the formation leader. AKA, i set a formation and do a 180 degree rotation of the formation, that is when the error occurs.
so each tank is given the formation position that is closest to them.
let's say i ask the formation of tanks to go from facing north to facing south. do you want the take in the leftmost position oriented north to now be in the rightmost position facing south, because that's how the formation would turn? or do you want leftmost tank facing north to now be the leftmost tank facing south
it sounds like you want the second one
you have to hand out the formation positions one by one
sorry for interrupting your typing - this is just to show what currently happens.
with linq, you can do
IDictionary<Unit, Vector3> CorrespondingPositions(
Vector3 leaderPosition,
List<Unit> units,
Vector3 orientation,
float gridSpacing=1f,
int columns=3) {
// orient a grid
var grid = GetOrientedGrid(columns=columns, rows=Mathf.Ceil(units.Count/columns), gridSpacing=gridSpacing);
// assign grid positions
// to the unit closest to them
// first enumerate every unit
return units.SelectMany(unit =>
// then enumerate every grid position
grid.Select(position =>
// return a tuple of the unit, the position and its distance from the grid position
(unit, gridPosition))
// sort by the distance
.OrderBy(tuple => (tuple.unit.position - tuple.gridPosition).magnitude)
// get the first appearnce of each unit
.Distinct(tuple => tuple.unit)
.ToDictionary(tuple => tuple.unit, tuple => tuple.gridPosition);
}
alright, ill give a crack integrating it. Can i ping you here if i have any problems later on?