[ad_1]

I have been engaged on a customized enemy "AI", the way in which it really works is it generates a degree inside a colliders bounds, then strikes the enemy in direction of the purpose. As soon as the enemy reaches it. The purpose is generated in a random completely different place. Kinda giving the impact that it is flying round randomly.

The one posts and data I may discover was eradicating wobbling or stuttering.
I believed possibly I may use some Perlin Noise after which add it as like an offset. However I could not work out a method to do it effectively. So does anybody know the way I can add an offset utilizing Perlin noise? The answer cant simply add a random offset in any other case it simply jitters round, it must be a clean wobble. That is the half that I am discovering troublesome.

Right here is my code (with some pointless elements cutout):

[Header("Enemy Settings")]
public EnemyType enemyType;
public float pace;
public float maxDistance;

[Header("Flight Settings")]
public BoxCollider2D flightBounds;
public Remodel flightBoundsPosition;
public bool stationaryWhenIdle;

[Header("Attack Settings")]
public EnemyAttackType attackType;
public EnemyAgression enemyAgression;
public float playerDetectionRadius;
public LayerMask playerLayer;

public float playerFollowSpeed;
public float chargeForce;
public float chargeDuration;
public float chargeCooldown;

// internals
non-public Rigidbody2D rb;
non-public Bounds boxBounds;
bool atPoint = false;
Vector2 level;
int dir;

void Replace() {
    if (enemyType == EnemyType.Strolling) {
        FlipEnemy();
        MoveEnemy(EnemyType.Strolling);
        AlignEnemy();
    }
    if (enemyType == EnemyType.Flying) {
        FlipEnemy();
        MoveEnemy(EnemyType.Flying);
        AlignEnemy();
    }
}

non-public void MoveEnemy(EnemyType sort) {
    if (sort == EnemyType.Flying) {
        // flight
        if (!stationaryWhenIdle) {
            level = GeneratePoint(false);
            float step = pace * Time.deltaTime;
            rework.place = Vector2.MoveTowards(rework.place, level, step);
        }

        // assault
        if (enemyAgression == EnemyAgression.Passive) return;
        Collider2D[] collider2Ds = Physics2D.OverlapCircleAll(rework.place, playerDetectionRadius, playerLayer);
        foreach (Collider2D col in collider2Ds) {
            if (attackType == EnemyAttackType.Observe) {
                float step = playerFollowSpeed * Time.deltaTime;
                rework.place = Vector2.MoveTowards(rework.place, col.rework.place, step);
                break;
            }
        }
    }
    else {
        rb.velocity = new Vector2(pace * dir, rb.velocity.y);
    }
}

non-public Vector2 GeneratePoint(bool isStart) {
    if (Vector2.Distance(rework.place, level) < 0.2f) atPoint = true;
    else atPoint = false;
    if (atPoint || isStart) {
        Vector2 place = new Vector2(
            Random.Vary(boxBounds.min.x, boxBounds.max.x),
            Random.Vary(boxBounds.min.y, boxBounds.max.y)
        );
        return place;
    }
    else return level;
}

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *