function [value,isterminal,direction] = schuss_event(t, y)

global z0 x0 var2 korrx korry korr1

if var2 == 1
    % Bricht Integration am Scheitelpunkt der Kurve ab.
    value = y(4);
    isterminal = 1;   
    direction = -1;   
elseif var2 == 2
    %Bricht die Integration am Nullpunkt ab.
    value = y(3);
    isterminal = 1;   
    direction = -1; 
elseif var2 == 3
    %Bricht die Integration auf Starthoehe ab falls z0>0.  
    if z0 > 0
        if (y(3) < z0) & (y(1)/z0+korrx < 1.5) & (y(1)/z0+korrx > 0) & (y(5)/z0+korry > -3) & (y(5)/z0+korry < 3)
            height = ((y(1)/z0+korrx) .* exp(-(y(1)/z0+korrx).^100 - (y(5)/z0+korry).^2));
            height = height/korr1*z0;
            value = y(3) - height;
        else 
            value = y(3);
        end
    else
        value = y(3);
    end
    isterminal = 1;   
    direction = -1;      
end