Create Unit

Now it is time to correctly configure your individual Unit prefab. This will later be used as a template for all units in your formations.

  1. Add Unit Script and NavMesh Agent

    1. Choose your desired 3D model for the unit and add it to the scene. Next add the Unit.cs component to it. It can be found under Assets\TopsonGames\Large Scale Formation System/Scripts/Unit.cs

    2. Adding the script will automatically add a NavMesh Agent component to the GameObject. If you cannot see the full agent component, please ensure you have the AI Navigation package installed via the Unity Package Manager. Installing the package should also be possible by pressing the Install button on the NavMesh Agent.

    3. Adjust the agent's size using the Radius, Height, and Base Offset fields to match the dimensions of your model.

    4. Drag the NavMesh Agent component into the Agent field of the Unit.cs script to create the reference

  2. Add a Collider

    1. Add a Collider component (e.g., Capsule Collider or Box Collider) to your Unit GameObject.

    2. The collider must be on the same GameObject as the "Unit.cs" script. It is essential for the system to detect units via mouse clicks or selection boxes.

    3. Ensure the collider's size matches the visual size of your unit.

  3. Assign Indicators and Waypoints:

    1. This system uses visual indicators for selection and movement targets. The recommended practice is to add the included Indicators and Waypoint prefab as a child of your Unit. It can be found under Assets\TopsonGames\Large Scale Formation System/Prefabs/Indicators and Waypoint

    2. Adjust the meshes and materials of the indicators to your liking. Assign the corresponding child objects to the fields in the "Unit.cs" script:

      1. Position Indicator: Shows the unit's current position and rotation, typically as a selection ring or decal below the unit.

      2. Waypoint: This is the invisible target transform that the unit actually moves towards.

      3. Waypoint Indicator: Used to visualize the new target position while a formation is being repositioned or its width is adjusted via drag-and-drop.

  4. Layer Assignment:

    1. For optimal performance and functionality, all units should be placed on their own dedicated layer (e.g., "Units"). This is crucial for the controller's raycasts to distinguish between ground and units. Select the appropriate layer for your unit in the Inspector. While leaving it on the "Default" layer can work, it is not recommended and may lead to deselection issues. A good tutorial on how to easily setup Layers and how they work can be found here https://vasundhara.io/blogs/use-layers-in-unity

  5. Create a Prefab:

    1. Once the Unit GameObject is fully configured, create a prefab by dragging it from the Hierarchy into your Project window. Once the preafb is created you can remove the Unit from the scene.

    2. With this step, the unit setup is now complete.

Last updated