Пример #1
0
    List <Vector3> ComputeTrajectory(out bool expectedCollision)
    {
        expectedCollision = false;
        float   duration      = 10;
        float   step          = Time.deltaTime * 5; //MAGIC NUMBER :(
        int     collisionTest = (int)(10 / Time.timeScale);
        Vector3 pos           = transform.position;
        Vector3 velocity      = launched ? rb.velocity : transform.TransformVector(Vector3.forward) * step * launchForce / 5; //MAGIC NUMBER :(

        // Gizmos.DrawLine(pos, pos + velocity);

        List <Vector3> points = new List <Vector3>();

        points.Add(pos);
        bool collision = false;
        int  i         = 0;

        for (float t = 0; !collision && t < duration; t += step)
        {
            Vector3 newPos        = pos + velocity * step;
            Vector3 forceAtnewPos = CelestialRigidBody.GetForceAt(newPos) * forceScale;
            // Gizmos.DrawSphere(newPos, 0.1f);
            //Gizmos.DrawLine(pos, newPos);
            pos      = newPos;
            velocity = velocity + forceAtnewPos;

            //crash prediction
            i++;
            if (i % collisionTest == 0)
            {
                collision = Physics.OverlapSphere(newPos, safeDiameter, layerMask).Length > 0;

                /* if (collision)
                 * {
                 *   Gizmos.DrawWireSphere(newPos, safeDiameter);
                 * }*/
            }
            points.Add(newPos);
        }
        expectedCollision = collision;
        return(points);
    }
Пример #2
0
 private void Update()
 {
     rb.AddForce(CelestialRigidBody.GetForceAt(this.transform.position) * forceScale);
 }