Formation Placement
Overview
The FormationPlacement component allows for dynamic placement of units within a game environment using by default mouse-driven input. It facilitates the positioning of units in predefined or dynamically calculated formations based on user interaction. This makes it suitable for strategy games or any application requiring organised unit deployment.
Properties
Ground Layer Mask: Layer mask used to determine valid ground positions during raycasts for unit placement.
Raycast Max Distance: The maximum distance for raycast to detect ground hits.
Custom Input: Optional GameObject that can provide custom input handling through components implementing the IInputControl interface. If not set, a default input handler is used.
Unit Formation: The component responsible for managing the unit formation. Changing this reference during active placement can result in errors. If placement is active, cancel it before proceeding.
Always Calculate Positions: When enabled, recalculates unit positions continuously during placement, making it useful for visual indicators before placement is finished.
Calculate Positions Interval Threshold: Sets the minimum time interval between position recalculations during active placements.
Place Visuals on Ground: Adjusts unit visuals to align with the ground.
Placement Visuals: Array of visual components that render unit placements. In provided components, line and unit positions are two separate visual components.
Public Interface
StartPlacement: Initiates the placement process. Placement will not start if conditions such as a missing UnitFormation component or unsuccessful raycast are met.
FinishPlacement: Finalizes the placement process, calculating positions for the current formation.
CancelPlacement: Cancels any active placement process, reverting any temporary changes.
Usage Example
Best Practices
Always verify that the ground layer mask is correctly set to avoid issues with raycasting. Using the same layer for structures for example, will result in line starting on the structures collider instead of ground.
Utilise custom input handlers to extend or modify the default placement behaviours.
Monitor performance when
Always Calculate Positions
is enabled, especially with large numbers of units.
Last updated