コード例 #1
0
ファイル: AirTraffic.cs プロジェクト: muramasa2402/DroNeS-LLV
        private static int FindIntersect(StaticObstacle obs, Vector3 start, Vector3 end, out int[] indices)
        {
            var dir  = end - start;
            var _dir = dir.normalized;

            Vector3 path(float m) => start + m * dir; // 0 < mu < 1

            int NumberOfIntersects = 0;

            float[] mu = new float[4];
            indices = new int[] { -1, -1 };
            for (int j = 0; j < obs.normals.Length; j++)
            {
                // if heading not parallel to surface
                if (Mathf.Abs(Vector3.Dot(_dir, obs.normals[j])) > epsilon)
                {
                    // Solve ray-plane intersection
                    // f(mu).n = P0.n
                    // where . is dot product, n is plane normal, P0 is a point on the plane, f(mu) is ray equation
                    mu[j] = Vector3.Dot(obs.verts[j] - start, obs.normals[j]) / Vector3.Dot(dir, obs.normals[j]);
                    if (Vector3.Distance(path(mu[j]), obs.position) < obs.diag / 2 && mu[j] > 0 && mu[j] <= 1)
                    {
                        indices[NumberOfIntersects++] = j;
                    }
                }
            }

            if (NumberOfIntersects > 1 && mu[indices[1]] < mu[indices[0]])
            {
                Swap(ref indices[0], ref indices[1]); // make sure the first index refers to the closer intersect
            }

            return(NumberOfIntersects);
        }
コード例 #2
0
ファイル: AirTraffic.cs プロジェクト: muramasa2402/DroNeS-LLV
 private static void SetAltitude(StaticObstacle obs, float alt)
 {
     obs.position.y = alt;
     for (int i = 0; i < obs.normals.Length; i++)
     {
         obs.normals[i].y = alt;
         obs.verts[i].y   = alt;
     }
 }
コード例 #3
0
ファイル: PlayerController.cs プロジェクト: sabasa28/AniBrawl
    public void OnStaticObstacleCollision(StaticObstacle hitBy)
    {
        float   funElevation = 0.5f;
        Vector3 dir          = transform.position - hitBy.transform.position;

        pushedCor = StartCoroutine(Pushed(new Vector3(dir.normalized.x, funElevation, dir.normalized.z) * hitBy.pushForce));
        Hurt(hitBy.damage);
        AkSoundEngine.PostEvent("Weapon_hit", gameObject);
        StartCoroutine(ImmunityTime());
    }
コード例 #4
0
ファイル: AirTraffic.cs プロジェクト: muramasa2402/DroNeS-LLV
 private static bool IsContained(StaticObstacle obs, Vector3 p)
 {
     for (int i = 0; i < 4; i++)
     {
         if (Vector3.Dot(p - obs.verts[i], obs.normals[i]) > 0)
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #5
0
ファイル: AirTraffic.cs プロジェクト: muramasa2402/DroNeS-LLV
 private static Vector3 FindOtherWaypoint(StaticObstacle obs, Vector3 start, Vector3 not)
 {
     foreach (var vert in obs.verts)
     {
         var point = vert + R_d * ((Vector3)vert - obs.position).normalized;
         if ((point - start).magnitude > epsilon && (point - not).magnitude > epsilon && (point - not).magnitude < obs.diag)
         {
             return(point);
         }
     }
     return(start);
 }
コード例 #6
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.CompareTag("Item"))
     {
         Item hitBy = collision.gameObject.GetComponent <Item>();
         pController.OnItemCollision(hitBy);
     }
     if (collision.gameObject.CompareTag("StaticObstacle"))
     {
         StaticObstacle hitBy = collision.gameObject.GetComponent <StaticObstacle>();
         pController.OnStaticObstacleCollision(hitBy);
     }
 }
コード例 #7
0
ファイル: AirTraffic.cs プロジェクト: muramasa2402/DroNeS-LLV
        } //Initialized presimulation

        private static void ExcludedVolume(StaticObstacle o)
        {
            o.size   += Vector3.one * R_d;
            o.size.y -= R_d;
            o.diag    = new Vector2(o.size.x, o.size.z).magnitude;
            var r = RotationY(o.orientation.y) * Vector3.right;
            var l = RotationY(o.orientation.y) * Vector3.forward;

            o.dx = r * o.size.x / 2;
            o.dz = l * o.size.z / 2;

            o.verts[0] = (Vector3)o.position + o.dz + o.dx; // ij
            o.verts[1] = (Vector3)o.position - o.dz + o.dx; // jk
            o.verts[2] = (Vector3)o.position - o.dz - o.dx; // kl
            o.verts[3] = (Vector3)o.position + o.dz - o.dx; // li
        }
コード例 #8
0
        private void Spawn()
        {
            if (SpawnIntervall == 0)
            {
                return;
            }

            StaticObstacle obstacle = new StaticObstacle();

            switch (Level)
            {
            case 1:
                obstacle = ObstacleFactory.GetStaticObstacle();
                break;

            case 2:
                obstacle = ObstacleFactory.GetStickyObstacle();
                break;

            case 3:
                obstacle = ObstacleFactory.GetStaticOrStickyObstacle();
                break;

            case 4:
                obstacle = ObstacleFactory.GetRandomObstacle();
                break;

            case 5:
                obstacle = ObstacleFactory.GetRandomObstacle();
                break;

            case 6:
                obstacle = ObstacleFactory.GetMovingOrStickyObstacle();
                break;
            }
            obstacle.Position = new Vector2(JamGame.ScreenWidth, ConveyorHitBox.Position.Y - ConveyorHitBox.Size.Height - obstacle.Hitbox.Height);
            Components.Add(obstacle);
        }
コード例 #9
0
ファイル: AirTraffic.cs プロジェクト: muramasa2402/DroNeS-LLV
        private static Vector3 FindWaypoint(StaticObstacle obs, Vector3 start, Vector3 end, int[] indices)
        {
            var     _dir = (end - start).normalized;
            Vector3 waypoint;

            if (indices[1] == -1)
            {
                // If only one intersetion detected sets the way point near the vertex clockwise from the
                // intersection point
                int num = FindIntersect(obs, start, end + obs.diag * _dir, out int[] indi);
                if (num > 0)
                {
                    return(FindWaypoint(obs, start, end + obs.diag * _dir, indi));
                }
            }

            Vector3 a;
            Vector3 b;

            if (Mathf.Abs(indices[1] - indices[0]) == 1 || Mathf.Abs(indices[1] - indices[0]) == 3)
            {
                // indices previously swapped to ensure 1 is bigger than 0
                // adjacent faces interseciton
                int j;
                if (Mathf.Abs(indices[1] - indices[0]) == 1)
                {
                    j = indices[1] < indices[0] ? indices[1] : indices[0];
                }
                else
                {
                    j = 3;
                }
                a        = obs.verts[j] + R_d * ((Vector3)obs.verts[j] - obs.position).normalized;
                b        = obs.verts[(j + 1) % 4] + R_d * ((Vector3)obs.verts[(j + 1) % 4] - obs.position).normalized;
                waypoint = ((a - start).magnitude > epsilon) ? a : b;
            }
            else
            {
                // opposite faces interseciton
                a = obs.verts[indices[0]] + R_d * ((Vector3)obs.verts[indices[0]] - obs.position).normalized;
                b = obs.verts[(indices[1] + 1) % 4] + R_d * ((Vector3)obs.verts[(indices[1] + 1) % 4] - obs.position).normalized;
                if ((a - start).magnitude > epsilon && (b - start).magnitude > epsilon)
                {
                    // Gets the waypoint with the smallest deviation angle from the path
                    waypoint = Mathf.Abs(Vector3.Dot((a - start).normalized, _dir)) >
                               Mathf.Abs(Vector3.Dot((b - start).normalized, _dir)) ? a : b;
                }
                else
                {
                    // I think its possible for opposite face intersection to obtain the same point again
                    // but I might be wrong, this is to prevent it
                    waypoint = ((a - start).magnitude > epsilon) ? a : b;
                }
            }
            foreach (var nf in NoFlys)
            {
                if (IsContained(nf, waypoint))
                {
                    waypoint = FindOtherWaypoint(obs, start, waypoint);
                }
            }
            return(waypoint);
        }