private void GetNextCheckpoint(int idxCheckpointHit)
    {
        //1st checkpoint away
        PointDistance pd1 = new PointDistance();

        pd1.idx            = NextCheckpointIndex(idxCheckpointHit);
        pd1.dist           = (this.transform.position - Checkpoints.transform.GetChild(pd1.idx).position).sqrMagnitude;
        pd1.directionCP    = Checkpoints.transform.GetChild(pd1.idx).position - this.transform.position;
        pd1.angFCP         = Vector3.SignedAngle(ai.directionF, pd1.directionCP, Vector3.up);
        pd1.hits           = Physics.RaycastAll(centerCar(), pd1.directionCP, (Checkpoints.transform.GetChild(pd1.idx).position - this.transform.position).magnitude);
        pd1.HasLineOfSight = (pd1.hits[0].transform.name.StartsWith(WallStartsWith) == true);

        //2nd checkpoint away
        PointDistance pd2 = new PointDistance();

        pd2.idx            = NextCheckpointIndex(idxCheckpointHit + 1);
        pd2.dist           = (this.transform.position - Checkpoints.transform.GetChild(pd2.idx).position).sqrMagnitude;
        pd2.directionCP    = Checkpoints.transform.GetChild(pd2.idx).position - this.transform.position;
        pd2.angFCP         = Vector3.SignedAngle(ai.directionF, pd2.directionCP, Vector3.up);
        pd2.hits           = Physics.RaycastAll(centerCar(), pd2.directionCP, (Checkpoints.transform.GetChild(pd2.idx).position - this.transform.position).magnitude);
        pd2.HasLineOfSight = (pd2.hits[0].transform.name.StartsWith(WallStartsWith) == true);

        //pick the next
        if (pd2.HasLineOfSight == true)
        {
            ai.idxTarget = pd2.idx;
        }
        else
        {
            ai.idxTarget = pd1.idx;
        }
    }
示例#2
0
        public void MovePlayer(Vector2 dir)
        {
            if (dir != Vector2.zero)
            {
                Dir = dir;
            }
            var childAngle = childStartAngle;

            childAngle            += dir.x * inclineAngleScale * inclineAngleX;
            childAngle            += dir.y * inclineAngleScale * inclineAngleY;
            child.localEulerAngles = childAngle;

            var forwerdRay = new Ray(transform.position - transform.forward, transform.forward);

            if (Physics.Raycast(forwerdRay, out var forwerdHit, Mathf.Infinity, mask))
            {
                var forwardPoints = PointDistance.GetUpRight(forwerdHit, transform.up, transform.right);
                Normal = forwardPoints.Normal;

                var upFV    = Vector3.ProjectOnPlane(cameraTransform.up, forwardPoints.Normal).normalized;
                var rightFV = Vector3.ProjectOnPlane(cameraTransform.right, forwardPoints.Normal).normalized;


                Debug.DrawLine(transform.position, transform.position + rightFV, Color.black);
                Debug.DrawLine(transform.position, transform.position + upFV, Color.black);
                Debug.DrawLine(forwerdHit.point, forwerdHit.point + forwardPoints.Normal, Color.red);

                var projectDir = (upFV * dir.y + rightFV * dir.x).normalized;
                var move       = projectDir * (speed * Time.timeScale);

                rigid.AddForce(moveForceMultiplier * (move - rigid.velocity), ForceMode.Force);

                rigid.AddForce((forwerdHit.point - transform.position).magnitude * -forwardPoints.Normal * gravity, ForceMode.Acceleration);
            }
        }
    private void GetFirstCheckpoint()
    {
        if (Checkpoints != null && Checkpoints.transform.childCount > 1)
        {
            ai.directionF = this.transform.TransformDirection(Vector3.forward);

            //forward points only
            List <PointDistance> pointdistances = new List <PointDistance>();
            for (int i = 1; i < Checkpoints.transform.childCount; i++)
            {
                if (IsPositionInFront(Checkpoints.transform.GetChild(i).position) == true)
                {
                    PointDistance pd = new PointDistance();
                    pd.idx         = i;
                    pd.dist        = (this.transform.position - Checkpoints.transform.GetChild(i).position).sqrMagnitude;
                    pd.directionCP = Checkpoints.transform.GetChild(i).position - this.transform.position;
                    pd.angFCP      = Vector3.SignedAngle(ai.directionF, pd.directionCP, Vector3.up);
                    pointdistances.Add(pd);
                }
            }
            pointdistances = pointdistances.OrderBy(x => x.dist).ToList();

            //least angle
            List <PointDistance> pds = new List <PointDistance>();
            pds.Add(pointdistances[0]);
            pds.Add(pointdistances[1]);
            pds.Add(pointdistances[2]);
            pds          = pds.OrderBy(x => x.angFCP).ToList();
            ai.idxTarget = pds[0].idx;
        }
    }
示例#4
0
        static void PointTest()
        {
            var firstPoint  = new Point3D(1, 1, 1);
            var secondPoint = new Point3D(1, 2, 2);

            Console.WriteLine(firstPoint);
            Console.WriteLine("{0:F2}", PointDistance.Distance(firstPoint, secondPoint));

            Console.WriteLine("Zero point: {0}", Point3D.PointO);

            var pathOfPoints = new PointPath();

            pathOfPoints.AddPoint(new Point3D(1, 2, 3));
            pathOfPoints.AddPoint(new Point3D(2, 51, 23));
            pathOfPoints.AddPoint(new Point3D(13, 12, 23));
            pathOfPoints.AddPoint(new Point3D(42, 2, 11));
            pathOfPoints.AddPoint(new Point3D(32, 2, 63));

            Console.WriteLine("Path\n" + pathOfPoints);

            PathStorage.SavePathToFile("MyPointPath.txt", pathOfPoints);
            var pathFromFile = PathStorage.ReadPathFromFile("MyPointPath.txt");

            Console.WriteLine("Path read from file\n" + pathFromFile);
        }
示例#5
0
        void LookAtPlayer()
        {
            Ray forwerdRay = new Ray(transform.position - transform.forward, transform.forward);

            if (Physics.Raycast(forwerdRay, out var forwerdHit, Mathf.Infinity, mask))
            {
                var forwardPoints = PointDistance.GetUpRight(forwerdHit, transform.up, transform.right);

                transform.LookAt(transform.position - forwardPoints.Normal, forwardPoints.Up.normalized);
            }
        }
示例#6
0
        private PointDistance GetPointWithMaxDistance(IEnumerable <PointDistance> points)
        {
            var maxPoint = new PointDistance();

            Parallel.ForEach(points, point =>
            {
                if (point.Distance > maxPoint.Distance)
                {
                    maxPoint = point;
                }
            });

            return(maxPoint);
        }
示例#7
0
        /// <summary>
        /// Crops the substrokes using a distance threshold.
        /// </summary>
        /// <param name="uncropped">The list of uncropped substrokes.</param>
        /// <returns>List of substrokes, including the keys, with only the points that fall
        /// within the bounding box</returns>
        private Substrokes CropSubstrokesDist(List <Substroke> uncropped)
        {
            // Crops the neighbors of a substroke based on a maximum distance
            // Remove the points that are greater than a set distance away from the substroke
            List <Substroke> cropped = new List <Substroke>();

            foreach (Substroke sub in uncropped)
            {
                cropped.Add(sub.Clone());
            }

            // List<Substroke> miniSubs = new List<Substroke>();

            // Create a list of all the points in the key substrokes
            List <Point> keyPoints = new List <Point>();

            foreach (Substroke key_sub in keysSub.SubStrokes)
            {
                foreach (Point pt in key_sub.Points)
                {
                    keyPoints.Add(pt);
                }
            }

            // Checks if the points in the substroke are close enough to the weighted center.  If they
            // are not, then crop them (the distance is large enough so that the keys will not be cropped.
            foreach (Substroke sub in cropped)
            {
                foreach (Point point in sub.Points)
                {
                    bool isNear = false;
                    foreach (Point keypoint in keyPoints)
                    {
                        PointDistance pd = new PointDistance(point, keypoint);
                        if (pd.distance(PointDistance.EUCLIDIAN) < (double)DISTANCE_THRESHOLD)
                        {
                            isNear = true;
                            break;
                        }
                    }
                    if (!isNear)
                    {
                        sub.PointsL.Remove(point);
                    }
                }
            }

            return(new Substrokes(cropped));
        }
示例#8
0
        private PointDistance GetMaxPointDistance(AreaPoints areaPoints)
        {
            var maxPoint = new PointDistance();

            Parallel.ForEach(areaPoints.GetPoints(), point =>
            {
                var distance = areaPoints.GetDistanceToCenter(point);

                if (distance > maxPoint.Distance)
                {
                    maxPoint = new PointDistance
                    {
                        Distance = distance,
                        Point    = point
                    };
                }
            });

            return(maxPoint);
        }
示例#9
0
    private void Update()
    {
        explosionFrame++;
        if (isExplosion)
        {
            if (explosionFrame > 4)
            {
                transform.GetChild(0).gameObject.SetActive(false);
            }
            if (explosionFrame > 30)
            {
                Destroy(gameObject);
            }
        }
        else
        {
            if (explosionFrame > 60)
            {
                isExplosion    = true;
                explosionFrame = 0;

                GetComponent <ParticleSystem>().Play();
                GetComponent <SphereCollider>().radius += bombRadius;
                transform.GetChild(0).localScale       += Vector3.one / 4;

                AudioManager.Instance.Play(se);
            }

            var forwerdRay = new Ray(transform.position - transform.forward, transform.forward);
            if (Physics.Raycast(forwerdRay, out var forwerdHit, Mathf.Infinity, mask))
            {
                var forwardPoints = PointDistance.GetUpRight(forwerdHit, transform.up, transform.right);
                transform.localPosition +=
                    (dir.x * forwardPoints.Right.normalized +
                     dir.y * forwardPoints.Up.normalized)
                    * speed;
            }
        }
    }
示例#10
0
    static void SetBlock()
    {
        Undo.RecordObjects(Selection.gameObjects.Select(o => o.transform).ToArray(), "set");
        var mask = LayerMask.GetMask(new string[] { "Mebiusu" });


        foreach (var gameObject in Selection.gameObjects)
        {
            var transform = gameObject.transform;

            var forwerdRay = new Ray(transform.position - transform.forward, transform.forward);

            if (Physics.Raycast(forwerdRay, out var forwerdHit, Mathf.Infinity, mask))
            {
                var forwardPoints = PointDistance.GetUpRight(forwerdHit, transform.up, transform.right);


                Vector3 upFV = forwardPoints.Up.normalized;


                transform.LookAt(transform.position - forwardPoints.Normal, upFV);
            }


            forwerdRay = new Ray(transform.position - transform.forward, transform.forward);



            if (Physics.Raycast(forwerdRay, out forwerdHit, Mathf.Infinity, mask))
            {
                var forwardPoints = PointDistance.GetUpRight(forwerdHit, transform.up, transform.right);



                transform.localPosition = forwerdHit.point + forwardPoints.Normal * length;
            }
        }
    }
示例#11
0
    void Set(Vector3 prev, Vector3 current)
    {
        Ray forwerdRay = new Ray(transform.position - transform.forward, transform.forward);


        Debug.DrawRay(forwerdRay.origin, forwerdRay.direction * 10);

        if (Physics.Raycast(forwerdRay, out var forwerdHit, Mathf.Infinity, mask))
        {
            var forwardPoints = PointDistance.GetUpRight(forwerdHit, transform.up, transform.right);


            var sa = current - prev;

            transform.localPosition += forwardPoints.Right.normalized * sa.x +
                                       forwardPoints.Up.normalized * sa.y +
                                       forwardPoints.Normal * sa.z;
        }

        forwerdRay = new Ray(transform.position - transform.forward, transform.forward);

        if (Physics.Raycast(forwerdRay, out forwerdHit, Mathf.Infinity, mask))
        {
            var forwardPoints = PointDistance.GetUpRight(forwerdHit, transform.up, transform.right);


            Vector3 upFV = forwardPoints.Up.normalized;

            Quaternion OriginalRot = transform.rotation;

            transform.LookAt(transform.position - forwardPoints.Normal, upFV);
            Quaternion NewRot = transform.rotation;

            transform.rotation = Quaternion.Slerp(OriginalRot, NewRot, smoothSpeed);
        }
    }
示例#12
0
    public void MoveBlock(Vector2 dir)
    {
        var forwerdRay = new Ray(transform.position - transform.forward, transform.forward);

        if (Physics.Raycast(forwerdRay, out var forwerdHit, Mathf.Infinity, mask))
        {
            var forwardPoints = PointDistance.GetUpRight(forwerdHit, transform.up, transform.right);

            var upFV    = forwardPoints.Up.normalized;
            var rightFV = forwardPoints.Right.normalized;

            Debug.DrawLine(transform.position, transform.position + rightFV, Color.black);
            Debug.DrawLine(transform.position, transform.position + upFV, Color.black);

            var move = upFV * dir.y + rightFV * dir.x;

            GetComponent <Rigidbody>().AddForce(-forwardPoints.Normal * 5, ForceMode.Acceleration);

            if (dir != Vector2.zero)
            {
                GetComponent <Rigidbody>().AddForce(move, ForceMode.VelocityChange);
            }
        }
    }