Create a system where the player can:
- Select units using a drag-selection or single-click.
- Issue a movement command to selected units by clicking on the ground.
-
Add RTSController:
- Create a
RTSController
node in your scene. - Attach the
RTSController.gd
script to it.
Screenshot Suggestion: Show the main scene with the
RTSController
node added and its inspector panel. - Create a
-
Add Managers:
- As children of the
RTSController
, add:- A
SelectionManager
node and attach theSelectionManager.gd
script. - A
CommandManager
node and attach theCommandManager.gd
script.
- A
Screenshot Suggestion: Show the
RTSController
withSelectionManager
andCommandManager
as child nodes. - As children of the
-
Create UnitEntity Scene:
- Create a new
UnitEntity
scene with:- A
Node3D
as the root (withUnitEntity.gd
attached). - A
Sprite3D
for the unit’s visual representation. - A
SelectableComponent
as a child of the root.
- A
Screenshot Suggestion: Show the
UnitEntity
scene hierarchy in the editor. - Create a new
-
Place Units in the World:
- Instance several
UnitEntity
scenes and position them in your game world. - Group them under a
Units
node for organization. - Ensure each unit has the
SelectableComponent
and is added to the"units"
group.
Screenshot Suggestion: Show units scattered in the world with the
"units"
group assigned in the inspector. - Instance several
-
Configure SelectionManager:
- In the
SelectionManager
script, ensureraycast_manager
is correctly assigned to the Raycaster node. - Add a
ColorRect
to the UI layer as the selection box and link it to theselection_box
property in the inspector.
Screenshot Suggestion: Show the
SelectionManager
with itsraycast_manager
andselection_box
properties configured. - In the
-
Input Mapping:
- Add input actions in the
Input Map
for:select
: For left mouse button.command
: For right mouse button.
Screenshot Suggestion: Show the input mappings in the project settings.
- Add input actions in the
-
Enable Selection Visualization:
- Ensure each unit’s
SelectableComponent
is configured with aSprite3D
and a shader for the selection ring.
Screenshot Suggestion: Show the
SelectableComponent
setup in the unit’s scene. - Ensure each unit’s
-
Raycaster Setup:
- Add a
Raycaster
node to the main scene and attach theRaycaster.gd
script. - Configure the raycaster’s collision layers to detect ground surfaces and units.
Screenshot Suggestion: Show the
Raycaster
node configuration in the inspector. - Add a
-
Implement Commands:
- In the
CommandManager
script:- Ensure the
issue_command
method supportsmove
commands. - Connect the selected units to their
StateMachine
and transition toMoveState
when a command is issued.
- Ensure the
Screenshot Suggestion: Highlight the
issue_command
logic in theCommandManager.gd
script. - In the
-
Test Selection:
- Run the game and test dragging the selection box or clicking on individual units to select them.
- Verify that selected units visually highlight using the
SelectableComponent
.
Screenshot Suggestion: Capture the drag-selection in action, highlighting units in the selection area.
-
Test Commands:
- After selecting units, right-click on the ground to issue a move command.
- Verify that the units move to the target position using
NavigationAgent3D
.
Screenshot Suggestion: Capture units moving toward the clicked position.
- Debug Logs:
- Add debug prints in the
RTSController
,SelectionManager
, andCommandManager
to ensure the correct units are selected and commands are issued.
- Add debug prints in the
- Enhancements:
- Add command feedback, such as a visual marker at the target position.
- Expand the command system to include additional commands like attack or patrol.