示例#1
0
    // Called once per frame
    void Update()
    {
        Vector2 pos = transform.position;

        if (GM.Instance.player == null)
        {
            return;
        }
        Vector2 lookAtPos = GM.Instance.player.transform.position;

        // Decide what direction to look towards
        Vector2 direction = lookAtPos - pos;

        WEP.acceleration = direction.normalized;

        // Only enable shooting if the turret has a shot lined up with the player
        float currentAngle = transform.eulerAngles.z;

        currentAngle = WeightedEnemyPhysics.normalDegrees(currentAngle);

        float targetAngle = Mathf.Atan2(WEP.acceleration.y, WEP.acceleration.x) * Mathf.Rad2Deg;

        targetAngle = WeightedEnemyPhysics.normalDegrees(targetAngle);

        float diff = targetAngle - currentAngle;

        diff = WeightedEnemyPhysics.normalDegrees(diff);

        SAP.shootingEnabled = (Mathf.Abs(diff) <= Mathf.Abs(aimAngleLeeway));
    }
示例#2
0
    // Initialize the degree clamp in the WEP
    private void initDegreeClamp()
    {
        WEP.clampPerp = true;
        Vector2 normal = transform.position - asteroid.transform.position;
        float   theta  = Mathf.Rad2Deg * Mathf.Atan2(normal.x, normal.y);

        float realDoF   = 360f - degreesOfFreedom;       // Have to do this to fix something...
        float minDegree = (90f - realDoF / 2) + theta;
        float maxDegree = (90f + realDoF / 2) + theta;

        WEP.minDegree = WeightedEnemyPhysics.normalDegrees(minDegree);
        WEP.maxDegree = WeightedEnemyPhysics.normalDegrees(maxDegree);
    }