Adjustments to Flocking, reducing delay...

Okay, hopefully this a simple adjustment, but my relative ‘noobness’ when it comes to coding means it takes me days to get anywhere.

I’m using the ‘flocking’ script from unify, but need to adjust some of the features, mainly the timing of the flock controller.

What I need is for the flock to follow the main player, which is does, however, the path the flock takes means that it doesn’t follow close enough. The idea is to have the flock surrounding the main player at all times… the bits of code I’ve identified that relates to this is…

function boidSteering () {
    while(true) {
        if (inited) {
            rigidbody.velocity = rigidbody.velocity + calc() * Time.deltaTime;
           
            // enforce minimum and maximum speeds for the boids
            var speed = rigidbody.velocity.magnitude;
            if (speed > maxVelocity) {
                rigidbody.velocity = rigidbody.velocity.normalized * maxVelocity;
            } else if (speed < minVelocity) {
                rigidbody.velocity = rigidbody.velocity.normalized * minVelocity;
            }
        }
    waitTime = Random.Range(0.3, 0.5);
    yield WaitForSeconds(waitTime);
    }
}

i’ve tried adjusting the waitTime, but that doesn’t have the desired affect.

the calc function mentioned in the above code is what I think I need to adjust, which is this…

function calc () {
    var randomize   = Vector3((Random.value *2) -1, (Random.value * 2) -1, (Random.value * 2) -1);
   
    randomize.Normalize();

    flockCenter = Controller.GetComponent("Boid Controller").flockCenter;
    flockVelocity = Controller.GetComponent("Boid Controller").flockVelocity;
    follow = chasee.transform.localPosition;
   
    flockCenter = flockCenter - transform.localPosition;
    flockVelocity = flockVelocity - rigidbody.velocity;
    follow = follow - transform.localPosition;
       
    return (flockCenter + flockVelocity + follow*2 + randomize*randomness);

So, any thoughts would be welcome, suggestions etc. I’ve tried a few things, but my knowledge base is limited, so nothing worked as I wanted, so I’ve gone back to the start.

If I get anything, I’ll upload as I do, so hopefully someone else can make use of it in the future.

Cheers, Russ