To make a group of objects flock together, please follow these steps:
- Create a Material object in the Project window and name it m_green, with Main Color tinted green.
- Create a Material object in the Project window and name it m_yellow, with Main Color tinted yellow.
- Create a 3D Cube GameObject named Cube-drone at (0,0,0). Drag the m_yellow material into this object.
- Add a Navigation | NavMeshAgent component to Cube-drone. Set the Stopping Distance property of the NavMeshAgent component to 2.
- Add a Physics RigidBody component to Cube-drone with the following properties:
- Mass is 1
- Drag is 0
- Angular Drag is 0.05
- Use Gravity and Is Kinematic are both unchecked
- Constraints Freeze Position: Check the Y-axis
- Create the following Drone C# script class and add an instance object as a component to the Cube-drone GameObject:
using UnityEngine;
using UnityEngine.AI;
public class Drone : MonoBehaviour {
private NavMeshAgent...