Exemple #1
0
    private Vector3 CastApproximateRayOnTerrain(Vector3 rayPos, Vector3 rayDir)
    {
        Terrain terr = Terrain.activeTerrain;

        if (rayDir.y >= 0.0f)
        {
            return rayPos.Horz().Full3D(terr.SampleHeight(rayPos));
        }

        while (rayPos.y > terr.SampleHeight(rayPos))
        {
            rayPos += rayDir;
        }

        return rayPos - (rayDir * 0.5f);
    }