コード例 #1
0
    public static float CalcTimeToHitPos(Vector2 curPos, Vector2 curFireVec, TankStateInfo aimingTankInfo, WeaponPartSchematic schematic, Vector2 targetPos)
    {
        float timeToHit = 0;

        Vector2 diffVec = targetPos - curPos;

        // We have to calculate three things: rotation time, travel time to in range, and bullet travel time.

        // First calculate rotation time.
        timeToHit += aimingTankInfo.CalcTimeToRotate(curFireVec, diffVec);

        // Next, calculate travel time.
        float moveAmount = Mathf.Max(diffVec.magnitude - schematic.Range, 0);

        if (moveAmount > 0)
        {
            Vector2 newPos = diffVec.normalized * moveAmount + curPos;
            timeToHit += aimingTankInfo.CalcTimeToReachPosWithNoRot(newPos);
        }

        // Finally, calculate bullet travel time.
        timeToHit += Mathf.Min(schematic.Range, diffVec.magnitude) / schematic.ShootImpulse;

        return(timeToHit);
    }
コード例 #2
0
    public static float CalcTimeToReachPos(TankStateInfo tankInfo, Vector2 targetPos)
    {
        Vector2 curPos = tankInfo.Pos;

        Vector2 diffVec = targetPos - curPos;

        float timeToReach = 0;

        timeToReach += Mathf.Min(tankInfo.CalcTimeToRotate(tankInfo.ForwardVec, diffVec), tankInfo.CalcTimeToRotate(tankInfo.ForwardVec.Rotate(180f), diffVec));
        timeToReach += tankInfo.CalcTimeToReachPosWithNoRot(targetPos);

        return(timeToReach);
    }