unity 4.x game ai programming 라는 책에서 나온 코드다..


flock이라고 무리 짓는거 구현하는것임



private Vector3 steer () { Vector3 center = controller.flockCenter - transform.localPosition; // cohesion Vector3 velocity = controller.flockVelocity - rigidbody.velocity; // alignment Vector3 follow = controller.target.localPosition - transform.localPosition; // follow leader Vector3 separation = Vector3.zero; foreach (Flock flock in controller.flockList) { if (flock != this) { Vector3 relativePos = transform.localPosition - flock.transform.localPosition; separation += relativePos / (relativePos.sqrMagnitude); } } // randomize Vector3 randomize = new Vector3( (Random.value * 2) - 1, (Random.value * 2) - 1, (Random.value * 2) - 1); randomize.Normalize(); return (controller.centerWeight * center + controller.velocityWeight * velocity + controller.separationWeight * separation + controller.followWeight * follow + controller.randomizeWeight * randomize); } }



굵게 표시한 곳이 이해가 안간다..


단위벡터라고 하면 걍 nomalize 를 쓰면 될텐데


왜 저랬을까..