#Group of Game Objects error

1 messages · Page 1 of 1 (latest)

little fox
terse scaffold
#

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.

stuck ledge
#

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?

terse scaffold
#

Yeah, I did not see that. You have 3 destination instead of 4.

little fox
little fox
stuck ledge
#

the code that lays out the formation is buggy

#

how is it supposed to work? describe it in terms of the UX

little fox
# stuck ledge 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.

stuck ledge
#

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

little fox
stuck ledge
#

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);
}
little fox
#

alright, ill give a crack integrating it. Can i ping you here if i have any problems later on?

stuck ledge
#

well

#

i don't know what your code is

#

i mean you sent me the code but to be honest i did not read it

#

you are trying to do this inside an update loop

#

that's playing on hard mode

#

you have to think about how to organize this stuff better