Exemplo n.º 1
0
    void CalcTrustersVectors()
    {
        Node       pathPoint = path.GetClosestPoint(transform.position);
        Quaternion rot       = pathPoint.center.rotation;

        //flyght line
        Vector3 thisLine        = pathPoint.center.position;
        Vector3 nextLinePos     = pathPoint.next.center.position;
        Vector3 previousLinePos = pathPoint.previous.center.position;

        thisLine        = thisLine + (pathPoint.center.rotation * Vector3.up * shipHeight);
        nextLinePos     = nextLinePos + (pathPoint.next.center.rotation * Vector3.up * shipHeight);
        previousLinePos = previousLinePos + (pathPoint.previous.center.rotation * Vector3.up * shipHeight);

        //estimate truster calc pos
        Vector3 shipZDist = DrawVectors(thisLine, transform.position, rot, false);

        Quaternion rotOther;
        float      otherzdelta;
        Vector3    otherLinePos;

        if (shipZDist.z > 0)
        {
            rotOther     = pathPoint.next.center.rotation;
            otherLinePos = nextLinePos;
        }
        else
        {
            rotOther     = pathPoint.previous.center.rotation;
            otherLinePos = previousLinePos;
        }
        Vector3 shipZDistOther = (Quaternion.Inverse(rotOther) * (transform.position - otherLinePos));
        float   zdeltaOther    = shipZDistOther.z;
        float   zdeltaTotal    = Mathf.Abs(shipZDist.z) + Mathf.Abs(zdeltaOther);
        float   zLerp;

        Vector3    finalLinePos;
        Quaternion finalLineRot;

        if (shipZDist.z > 0)
        {
            zLerp        = (shipZDist.z / zdeltaTotal);
            finalLinePos = Vector3.Lerp(thisLine, nextLinePos, zLerp);
            finalLineRot = Quaternion.Lerp(pathPoint.center.rotation, pathPoint.next.center.rotation, zLerp);
        }
        else
        {
            zLerp        = (zdeltaOther / zdeltaTotal);
            finalLinePos = Vector3.Lerp(previousLinePos, thisLine, zLerp);
            finalLineRot = Quaternion.Lerp(pathPoint.previous.center.rotation, pathPoint.center.rotation, zLerp);
        }

        //draw force points
        trustDirs = new Vector3[4];
        for (int i = 0; i < thrusters.Length; i++)
        {
            Vector3 pointBall = GetDrawVectors(i, finalLinePos, thrusters[i].transform.position, finalLineRot, false);
        }
    }