Arrival of formation to destination

IEmperator

New member
1539962565455.png

Hi to all!

I am wondering if i could get some help with offsetting a formation's destination position in a way that when they arrive the formation's centre is touching the destination marker.

I have bee able to have the leader at the back row as the image shows, which works just fine but now the formation reaches the set destination in an odd way so i was trying to offset the target destination with the half of the (separation.Value.x * formationRowsCnt) and half of (separation.Value.y * formationCollumnCnt) but it does not seam to work.

Any suggestion would be greatly appreciated!
 

Justin

Administrator
Staff member
Are you referring to the rotated agents? The agents will position themselves around the rotation of the leader so if you prevent the leader from rotating then it should end correctly. You may be able to do this by increasing the stopping distance on the navmeshagent.
 

IEmperator

New member
Are you referring to the rotated agents? The agents will position themselves around the rotation of the leader so if you prevent the leader from rotating then it should end correctly. You may be able to do this by increasing the stopping distance on the navmeshagent.

Hi Justin,

Thanks for the response, no i was not referring to the rotation of the arrival. As the image on the left shows right now the group stops when the leader arrives at the destination marker, what i am after is a way to calculate an offset of the destination position so that the leader stops in a way that group centre is where the destination marker is at like in the second image bellow.

FYI: I changed the return value of the overriden FormationPosition() function in the grid formation task to change the leader's position in the group:
return leaderTransform.TransformPoint(-separation.Value.x * column, 0, separation.Value.y * row + zLookAhead);

1540034725582.png1540034695060.png
 

Justin

Administrator
Staff member
Ahh, I see. This gets a little tricky because instead of the followers being relative to the leader, they instead should be relative to the offset of the leader. I haven't tried it myself but if you first apply an offset to the leader to get the center you should then be able to calculate a second offset for each unit.
 

IEmperator

New member
Ahh, I see. This gets a little tricky because instead of the followers being relative to the leader, they instead should be relative to the offset of the leader. I haven't tried it myself but if you first apply an offset to the leader to get the center you should then be able to calculate a second offset for each unit.
Hi Justin,

Indeed that is what i am attempting, however having trouble applying the offset correctly, in some cases it works in others is not the following code was trying to apply the offset based on the +/- sign of the marker's world position and as i said sometimes it is fine sometimes or it fails completely.

I tried all the adding subtracting combinations to no avail. I am sure i am missing something. Offsetting the leader's destination should works and it does just need to figure out the correct way to offset it.

private void CenterOffsetTargetDestination()
{
this.targetDestination = this.formationAgent.MeUnit.MyGroup.DestinationMarker.transform.position;
this.targetPosOffset.x = (float)(separation.Value.x * formationRowsCnt) / 2.0f;
this.targetPosOffset.z = (float)(separation.Value.y * formationCollumnCnt) / 2.0f;
this.offseted.x = targetDestination.x < 0 ? targetDestination.x + targetPosOffset.x : targetDestination.x - targetPosOffset.x;
this.offseted.y = targetDestination.y;
this.offseted.z = targetDestination.z < 0 ? targetDestination.z - targetPosOffset.z : targetDestination.z + targetPosOffset.z;
if(isFormationLeader)
Debug.Log(this.formationAgent.Name + " R: " + formationRowsCnt + " C: " + formationCollumnCnt + " " + targetDestination.ToString() + " + " + targetPosOffset.ToString() + " = " + offseted);
}
 
Top