pegasusejder
New member
In my game, I gave the army a few attack behaviors, one of which was the Leapfrog behavior. There is no problem with the Leapfrog behavior directly, but I have a problem like this;
There is a problem here, infantry soldiers can only go on roads (yellow area seen in the picture) and cannot pass through places like forests (blue area). While it follows the road properly in other behaviors, it constantly tries to go to the blue area in Leapfrog behavior and the army cannot advance. It probably happens because it only advances on the "z axis".
In general, I added to the SetDestination function in case they cannot go on their own path,
If there is no path to the selected point, I set the closest point to that point. This works properly in other behaviors, but this does not work properly in Leapfrog. What can I do about this? Can anyone help?
There is a problem here, infantry soldiers can only go on roads (yellow area seen in the picture) and cannot pass through places like forests (blue area). While it follows the road properly in other behaviors, it constantly tries to go to the blue area in Leapfrog behavior and the army cannot advance. It probably happens because it only advances on the "z axis".
In general, I added to the SetDestination function in case they cannot go on their own path,
public Vector3 ControlPathPoint(Vector3 destination)
{
NavMeshHit hit;
UnitInformation unitInformation = navMeshAgent.GetComponentInParent<UnitInformation>();
if (unitInformation == null) return destination;
if(unitInformation.unitSubType == UnitSubType.Cavalry)
{
if (NavMesh.SamplePosition(destination, out hit, 40f, NavMesh.AllAreas))
{
return hit.position;
}
else return destination;
}
if (NavMesh.SamplePosition(destination, out hit, 40f, NavMesh.GetAreaFromName("Road")))
{
return hit.position;
}
else return destination;
}
If there is no path to the selected point, I set the closest point to that point. This works properly in other behaviors, but this does not work properly in Leapfrog. What can I do about this? Can anyone help?