I’m not clearly sure what you trying to achieve there but
toTarget = target.position - submarine.position;
relativeHeading = submarine.Heading.Dot(target.heading); // heading is normalized vector pointing in heading direction
if(toTarget.Dot(submarine.heading) > 0 && (relativeHeading < -0.95)) // acos(0.95) = 18 degs
{
target is ahead of submarine
}
else
{
target is not ahead
}