[Chapter 18] Dampening

Hello!
Correct me if I am wrong, but I guess that function does not right:

float2 dampening(Boid boid) {
** float2 velocity = float2(0);**
** if (abs(boid.velocity.x) > limit) {**
** velocity.x += boid.velocity.x / abs(boid.velocity.x) * attenuation;**
** }**
** if (abs(boid.velocity.y) > limit) {**
** velocity.y = boid.velocity.y / abs(boid.velocity.y) * attenuation;**
** }**
** return velocity;**
}

I mean, our goal is to dampen the effect of the escaping behavior. I don’t see it in this line:
velocity += … dampeningVector * dampeningWeight
From the function dampening above we get vector the same direction as our main velocity.
Many thanks)

Hmm. You may be on to something here. I’ll have to review the code and get back to you.

1 Like

I’m still waiting for you…:slight_smile:

1 Like

I’m working on the code from first principles right now :innocent:.

1 Like

@harmansmith - sorry for taking so long. I wanted to get it right for the next edition, and make it more interactive. I took out the dampening, because the way I’m doing it now, with minimum and maximum speeds, it doesn’t need it.

Flocking.zip (373.9 KB)

I hope you enjoy it :slight_smile: . If there’s anything you don’t understand, or if I’ve stuffed up, please let me know!

(The predator bounces, whereas the other boids wrap. This has the effect of when the predator catches his prey, he holds onto it until they reach the edge and the prey escapes by wrapping.)

1 Like