Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[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 *