Here is a quick example of a basic flocking system I created. The flock of circles is simulated to follow after where the mouse is positioned in the game screen. The position of the mouse is tracked through a screen raycast that hits the background plane. The flock is set up with a behavior to also avoid colliding with each other which gives it some more realistic movement.
One of the key takeaways from this little programming project was the system design aspect. The flock system manager contains a list of all the flock agents and provides the agents with system context. The individual behaviors are managed at the flock agent level.
As an added benefit I feel like I've gotten a lot better at moving objects with forces in 3D space and how to use simple Vector Math.
The most difficult vector math concept was dot product. It wasn't that the math was difficult but the fact that I had misinterpreted the supporting image diagram which led me to repeatedly incorrectly using the formula and wondering why it wasn't working. The goal of the dot product I had for my project was to find the Vector3 location for where the red dot should be along the bottom horizontal line based on the box above.
I used the dot product to make the yellow arrows follow a predetermined path. If the predicted position of the yellow arrow is too far from the target red dot it would trigger a steering correction for it to move again back towards the path.
The final recent project was a tutorial on how to create a editor script that can read a CSV file and convert it into a scriptable object. Pretty handy in the future in the scenario that I have a lot of data that needs to be managed or changed.
No comments:
Post a Comment