Exemplo n.º 1
0
        public List <Vector3> ForwardSimulate(RigidBody rigidBody, int totalPoints, int ticksBetweenPoints)
        {
            List <Vector3> futurePoints = new List <Vector3>();

            float timeStep = Time.fixedDeltaTime;

            RigidBody myClone = rigidBody.DeepCopy();

            int totalTicks = totalPoints * ticksBetweenPoints;

            for (int index = 0; index < totalTicks; ++index)
            {
                foreach (var attractor in attractors)
                {
                    attractor.ApplyForce(myClone);
                }

                myClone.OnFixedUpdate();

                if ((index) % ticksBetweenPoints == 0)
                {
                    futurePoints.Add(myClone.position);
                }
            }

            return(futurePoints);
        }
Exemplo n.º 2
0
        public PathResult ForwardSimulate(RigidBody rigidBody, int totalPoints, int ticksBetweenPoints, Vector3 shipOffset)
        {
            PathResult     pathResult   = new PathResult();
            List <Vector3> futurePoints = new List <Vector3>();

            pathResult.FuturePoints = futurePoints;
            pathResult.State        = FutureState.OK;

            float timeStep = Time.fixedDeltaTime;

            RigidBody myClone = rigidBody.DeepCopy();


            int totalTicks = totalPoints * ticksBetweenPoints;

            for (int index = 0; index < totalTicks; ++index)
            {
                foreach (var attractor in attractors)
                {
                    attractor.ApplyForce(myClone);
                }

                myClone.OnFixedUpdate();

                foreach (var attractor in attractors)
                {
                    if (Vector3.Distance(attractor.transform.position, myClone.position) < attractor.GetComponent <SphereCollider>().radius)
                    {
                        //we've hit this attractor
                        pathResult.State = FutureState.PlanetHit;
                        break;
                    }
                }

                if (Vector3.Distance(ActiveCheckpoint.transform.position, myClone.position) < ActiveCheckpoint.GetComponent <SphereCollider>().radius *10)
                {
                    pathResult.State = FutureState.CheckpointHit;
                }

                if (pathResult.State != FutureState.OK)
                {
                    break;
                }

                if ((index) % ticksBetweenPoints == 0)
                {
                    futurePoints.Add(myClone.position + shipOffset);
                }
            }

            return(pathResult);
        }