Use a control map to automatically use the base attack on a clicked combatant.
Control maps are used to bind input keys to actions, e.g. using the base attack, an ability or item. A control map will use the first useable action it finds for an input key, i.e. you can bind multiple actions to a single key. You can learn more about control maps in this documentation.
In this tutorial, we’ll the player (or currently action-selecting combatant) automatically use the base attack when clicking on an enemy, without having to first select the Attack command in a battle menu.
This tutorial is based on the 2D RPG Quickstart and 3D RPG Quickstart tutorial series, but you can use this for any kind of project.
Input Key #
First, we’ll set up a new input key for the mouse click.
Open the Makinom editor, navigate to Base/Control > Input Keys and add a new input key.
- Name
Set to: Left Click
Input ID Setting 0 #
- Input Origin
Select Mouse. - Mouse Button
Set to 0.
I.e. the left mouse button (1 for right, 2 for middle). - Click Count
Set to 1.
A single click will be used. - Input Handling
Select Down.
I.e. when the left mouse button is clicked down.
Control Map #
Next, we’ll set up the control map.
Navigate to Base/Control > Control Maps and add a new control map (or change the default one, if you haven’t used them yet).
- Name
Set to: Click Attack
The Useable In settings define in which battle systems (or the field) the control map can be used – the default settings should be fine for us, i.e. using them in all battle systems.
- Field
Disable this setting. - All Battle Systems
Enable this setting. - Grid Battles
Select Ignore.
Additionally, we’ll allow using the control map while the combatant is selecting actions.
- While Choosing
Enable this setting.
Control Key 0 #
We’ll add a control key – they bind input keys to actions in the control map.
Click on Add Control Key to add one.
Input Settings #
The input settings handle which input key and when it can be used (e.g. limited to being on the ground or moving at a certain speed).
- Input Key
Select Left Click.
Action Settings #
The action settings handle which action will be used when the input key is used.
- Type
Select Action.
We’ll use a defined action. - Action Type
Select Attack.
This’ll use the combatant’s base attack.
We only want to use this when the mouse cursor is over an available target and directly use that combatant as the target for the attack.
- Only Cursor Over Target
Enable this setting.
I.e. the control key will only be used if the cursor is over a valid target for the action.
Additionally you can enable the Only In Range setting to limit the use to being in use range of the action. - Use Cursor Over Target
Enable this setting.
This’ll use the combatant the cursor is over as target for the action.
Additionally, we’ll also prevent a target selection from being opened.
- No Target Selection
Enable this setting.
Conditions #
Using the control key can be limited by additional conditions – we’ll disable using it during target selections, to not interfere with regular click-target selection.
- During Target Selection
Disable this setting.
Combatants General Settings #
With the control map set up, all we need to do is add it for our combatants. You can either add it to individual combatants or as default setup for all combatants – that’s what I’ll do.
Navigate to Combatants > Combatants > General Settings and change the following settings.
Base Settings > Default Control Maps #
Click on Add Control Map.
- Control Map
Select Click Attack.
Battle System Changes #
Right now, our setup would already work, but only for the player combatant itself – e.g. having multiple combatants in the player group during a turn based battle would only use the control map for the group leader (the player).
We’ll change that by enabling control maps for the currently selecting combatants. This automatically uses control maps for the (player group) combatant that’s selecting actions.
Navigate to Battles > Battle System and select your battle system. Since I’m building upon the 3D RPG Quickstart tutorials, I’ll use the Turn Based battle system.
Turn Based Settings > Other Options #
- Selecting Control Map
Enable this setting.
Save Changes #
And that’s it – click on Save Settings to save the changes.
Testing #
Hit play and test clicking on enemies during battle.
It works!
Tip! Raycast Settings #
Clicking on combatants doesn’t work?
This is handled by raycasts, i.e. you need to make sure your combatants are on a layer that is hit by the raycast. Also, make sure no other thing might be in the way between the screen and the combatant. It’s a good idea to have combatants on a dedicated layer and only use that for the raycast.
You can find the raycast settings for this in Battles > Target Settings in the Target Selection > Mouse/Touch Control settings.