This uses the same motion updating in the previous post, but replaces the contraction step (i.e., boidLocations = 0.995 boidLocations) with a projection to the sphere. Because location is constrained, the step away from the “enemy” can be larger and things don’t fly away, making it too large destroys the flocking behavior.