Grid Positioner Setup (v5.0)
The GridPositioner is the core component that handles grid positioning, targeting, and coordinate system management for v5.0.0.
For a complete setup overview, see Getting Started Setup.
Overview
The GridPositioner manages the spatial relationship between world coordinates and grid coordinates, providing the foundation for all building and targeting operations.
Template Types
Standard Grid Positioner
- File:
grid_positioner_stack.tscn - Use Case: Top-down games, standard rectangular grids
- Coordinate System: 2D Cartesian coordinates
Isometric Grid Positioner
- File:
grid_positioner_stack_isometric.tscn - Use Case: Isometric games, diamond-shaped grids
- Coordinate System: Transformed isometric coordinates
Node Hierarchy
GridPositioner2D (Node2D) - Main positioning controller
├── TargetingShapeCast2D (ShapeCast2D)
│ ├── Shape: RectangleShape2D or custom indicator shape
│ ├── Script: targeting_shape_cast_2d.gd
│ └── Collision mask: 2048 (for grid detection)
└── ManipulationParent (Node2D)
├── Script: manipulation_parent.gd
└── IndicatorManager (Node2D)
└── Script: indicator_manager.gd
Note: GridTargetingSystem is a separate system node that lives in the Systems hierarchy, not as part of the GridPositioner stack.
Component Breakdown
GridPositioner2D
The main node that manages grid positioning and sits at the top of the positioning stack hierarchy:
Script: grid_positioner_2d.gd
Hierarchy Position:
GridPositioner2D (Top of positioning stack)
├── TargetingShapeCast2D (Child - handles collision detection)
└── ManipulationParent (Child - manages visual feedback)
└── IndicatorManager (Grandchild - renders indicators)
Key Properties:
z_index: Rendering layer (typically 1000 for grid overlay)- Grid coordinate transformation logic
- Integration with targeting and manipulation systems
- Input processing toggle controls
Input Toggling: The GridPositioner2D controls whether mouse and keyboard input is processed for grid operations:
| |
Core Functions:
| |
Objects Under GridPositioner2D:
- TargetingShapeCast2D: Direct child, handles mouse collision detection
- ManipulationParent: Direct child, manages all visual feedback
- IndicatorManager: Child of ManipulationParent, renders placement previews and validation feedback
TargetingShapeCast2D
Handles grid targeting and collision detection:
Script: targeting_shape_cast_2d.gd
Configuration:
- Shape: Defines the targeting area
- Standard: RectangleShape2D (16x16 pixels)
- Isometric: Custom diamond shape
- Collision Mask: 2048 (grid detection layer)
- Target Position: Vector2(0, 0) for local targeting
Key Properties:
| |
Functionality:
- Detects grid cells under cursor
- Provides targeting feedback
- Integrates with selection systems
Visual Feedback
Visual grid feedback is handled by the IndicatorManager within ManipulationParent:
Script: indicator_manager.gd
Features:
- Placement preview indicators
- Target highlighting
- Validation feedback (valid/invalid placement)
- Cell boundary rendering
Customization:
- Indicator colors for different states
- Preview transparency
- Highlight effects
ManipulationParent
Container for manipulation operations:
Script: manipulation_parent.gd
Purpose:
- Manages object manipulation state
- Coordinates with IndicatorManager
- Handles drag and drop operations
Key Functions:
| |
IndicatorManager
Manages visual indicators for placement and manipulation:
Script: indicator_manager.gd
Responsibilities:
- Show placement previews
- Display validation feedback
- Handle manipulation indicators
- Manage indicator lifecycle
Setup Instructions
1. Choose Template Type
Select the appropriate template based on your game type:
| |
2. Add to Scene
- Create a
GridPositionernode in your world - Instance the chosen template
- Position appropriately in your scene hierarchy
3. Configure Targeting
Set up the TargetingShapeCast2D:
| |
4. Connect to Systems
Wire the GridPositioner to other systems:
| |
Input Toggling Usage
Common Scenarios
1. UI Menu Open:
| |
2. Cutscene or Dialog:
| |
3. Different Game States:
| |
Input State Management
| |
Configuration Options
Grid Size
Configure grid cell size in your settings:
| |
Coordinate Systems
Standard (Cartesian)
Grid: (0,0) (1,0) (2,0)
(0,1) (1,1) (2,1)
(0,2) (1,2) (2,2)
World: Standard 2D coordinates
Isometric
Grid: Same coordinate system
World: Transformed for isometric view
Collision Layers
Set up proper collision layers:
| |
Integration Examples
Top-Down Game Setup
| |
Isometric Game Setup
| |
Custom Grid Positioners
Creating Custom Templates
- Copy an existing template
- Modify the hierarchy as needed
- Customize scripts for special behavior
- Save as new template
Custom Coordinate Systems
| |
Performance Considerations
Optimization Tips
- Batch Operations: Process multiple grid operations together
- Spatial Partitioning: Use spatial data structures for large grids
- Lazy Updates: Only update visible portions of the grid
- Caching: Cache coordinate conversions when possible
Memory Management
| |
Troubleshooting
Common Issues
Incorrect Coordinate Conversion
- Check grid_size settings
- Verify transform properties
- Ensure proper parent hierarchy
Targeting Not Working
- Verify collision mask settings
- Check layer assignments
- Ensure TargetingShapeCast2D is enabled
Visual Feedback Missing
- Check IndicatorManager visibility
- Verify indicator materials
- Ensure proper z_index ordering
- Check ManipulationParent is properly connected
Debug Tools
| |
Best Practices
1. Consistent Coordinate Usage
- Always use grid coordinates for game logic
- Convert to world coordinates only for rendering
- Maintain coordinate system documentation
2. Proper Layer Management
- Use dedicated layers for grid detection
- Keep building objects on separate layers
- Document layer assignments
3. Performance Monitoring
- Monitor grid operation performance
- Profile coordinate conversion functions
- Optimize for target frame rate
4. Testing Coverage
- Test coordinate edge cases
- Verify targeting accuracy
- Validate manipulation behavior
Advanced Features
Multi-Grid Support
| |
Dynamic Grid Resizing
| |
Grid Validation
| |
The GridPositioner serves as the foundation for all grid-based operations in v5.0.0, providing robust coordinate management and targeting capabilities for various game types and use cases.