🧊3D Cube
Learn more about cube selection area
Last updated
Learn more about cube selection area
Last updated
This feature utilises mouse drag start and current screen positions to cast rays onto the ground, configuring the position and scale of the selection cube in world space accordingly. The MaxSelectionDistance
property in the UnitSelector configuration sets the maximum distance allowed for the ground raycast.
Note: Prefab is named 3D Cube Selection Area.
Customise the appearance and behaviour of the selection cube to suit your game's needs.
Update Material: To alter the appearance of the selection cube, you can either apply a custom material or modify the properties of the existing material attached to the MeshRenderer component.
Ground Layer Mask: Specifies the layer mask used for ground detection via physics raycast.
Minimal Height: Sets the minimum height of the selection cube. Setting this to zero would render the cube invisible and unable to detect any units within its area. This configuration ensures the cube remains visible and functional, especially when the start and current drag positions hit the ground at the same Y value, which would otherwise result in a calculated height of zero.
The 3D cube selection offers a variety of detection methods tailored to meet different selection needs within a game environment. Note that rotation is not currently considered with some detection methods. Choose the detection type that best fits the orientation and dimensional variations of your units along the X and Z axes.
Detection Types:
Collision
Description: This method uses physics overlap checks to detect colliders within the selection area. It leverages Unity’s physics engine to identify units that intersect with the cube’s boundaries.
Consideration: This approach may not be optimal for scenarios where the camera captures thousands of units, as it could potentially affect performance.
Position
Description: Checks if a unit’s position lies within the selection area’s bounds. This method is effective for simple positional checks, ensuring that only units physically inside the cube are selected.
RendererBounds
Description: Determines selection by checking if the cube's boundaries intersect with a unit's renderer bounds. This method does not consider rotation, making it suitable when rotation does not significantly affect the selection relevance.
Optimisation: Renderer is retrieved using GameObject.GetComponentInChildren<Renderer>()
method, which can lead to two things; performance impact and selecting the wrong renderer if game object has more than one. Using RendererSelectionBounds component with specified renderer and CustomBounds detection type will optimise this detection process.
CustomBounds
Description: Similar to RendererBounds, this method determines detection based on intersecting boundaries. And like with RendererBounds, rotation is not considered.
Requirement: This detection type requires for selectable units to have a component that implements ISelectableBounds. There are few available out of the box, you can find them here Selection Bounds.
Select the appropriate detection type based on the specific needs and characteristics of the scene and units. For example, scenarios involving units with significant size differences or varying orientations may benefit from the Position or CustomBounds methods, which can offer more precise selection accuracy, scenarios with smaller unit count and precise detection can use Collision methods.