In this tutorial we’ll set up a throwable grenades.
The grenade is thrown to a position the player selects and explodes after some time. The time will stand still while selecting the position to throw to, and we’ll display a selection cursor following the mouse (in the game world).
We’ll set up:
- schematic to pulse the cursor (scaling it up/down)
- schematic to throw the grenade
- schematic to explode the grenade
- grenade item
- update the control map
- add grenades to the player’s start inventory
- set up the grenade and cursor prefabs
Let’s get to it.
Cursor Pulse Schematic #
This one will be pretty simple – it’ll scale the cursor up and down and restart, until the game object is destroyed again (which stop’s it’s Auto Machine that uses the schematic).
Navigate to Schematics and start working on a new schematic.
Settings #
We’ll disable using Unity and Makinom timescales – i.e. the schematic will perform in unscaled time.
This is needed, since the cursor is displayed during timescale being set to 0.
- Unity Time Scale
Disable this setting. - Makinom Time Scale
Disable this setting.
Change Scale #
Add Node > Movement > Movement > Change Scale
We’ll use this node to scale the game object over time.
The cursor’s game object has a scale of 5 (on all axes) when it’s spawned, we’ll increase the scale to 5.5.
- Object (Scaling Object)
Select Machine Object. - Vector3 Type (Scale)
Select Value > Value. - Value
Set to X=5.5, Y=5.5, Z=5.5. - Fade Scale
Enable this setting. - Time
Select Value > Value.
Set the value to 0.5. - Wait
Enable this setting. - Interpolation
Selec Quadratic > Quadratic In + Out.
Change Scale #
Duplicate the Change Scale node. We’ll scale back to 5.
- Value
Set to X=5, Y=5, Z=5.
Restart Schematic #
Add Node > Machine > Restart Schematic
This node will restart the schematic in the next frame. No further settings needed.
And that’s it for the schematic. Click on Save Schematic to save it, e.g. as CursorPulse.
Grenade Throw Schematic #
The position we throw the grenade to is selected using a raycast during the player’s target selection – this is availabe as the Starting Object of the schematic (it’s an empty game object that’ll be destroyed after the item action ended).
Our grenade throw will be similar to the Spit Attack we already set up, i.e. we’ll rotate to the target, throw the thing and activate it … more or less.
Create a new schematic.
Settings #
We’ll block the player controls.
- Block Player Control
Enable this setting.
Prefabs #
We also add the grenade prefab.
Click on Add Prefab Resource.
- Prefab
Select the Grenade prefab.
You can find it in Assets/Tutorial Assets/Prefabs/Weapons/.
Rotate To #
Add Node > Movement > Rotation > Rotate To
We’ll do a quick rotation to the Starting Object.
- Object (Rotating Object)
Select Machine Object. - Rotate Component
Select Transform. - Lock Rotation
Enable X and Z. - Rotation Target
Select Game Object. - Object
Select Starting Object. - Fade Rotation
Enable this setting. - Time
Select Value > Value.
Set the value to 0.1. - Wait
Enable this setting. - Interpolation
Select Linear.
Play Sound #
Add Node > Audio > Audio > Play Sound
- Object (Play On)
Select Machine Object. - Audio Clip Asset
Select swoosh01. - Play One Shot
Enable this setting. - Set Pitch
Enable this setting. - Random Pitch
Enable this setting. - Pitch
Set to 0.8. - Pitch 2
Set to 1.2.
Combatant Animation #
Add Node > Animation > Combatant > Combatant Animation
We’ll play the combatant’s attack animation (looks like a throw without the staff).
- Object
Select Machine Object. - Animation Type
Select Attack. - Wait
Enable this setting. - Normalized Time (Wait)
Set to 0.08. - Store Duration
Enable this setting. - Normalized Time (Store Duration)
Set to 0.9. - Variable Key
Set to wait. - Variable Origin
Select Local.
Consume Costs #
Add Node > Battle > Action > Consume Costs
This node will consume the action’s use costs, i.e. remove 1 grenade from the user’s inventory.
No further settings.
Spawn Prefab #
Add Node > Game Object > Prefab > Spawn Prefab
We’ll now spawn the grenade prefab.
You could also use the position of the combatant’s hand (or any other child object) if you want, but roughly positioning it with an offset is enough.
- Prefab
Select Prefab 0. - Target Type
Select Object. - Object (Target Object)
Select Machine Object. - Local Space
Enable this setting. - Offset
Set to X=0, Y=1, Z=0.5. - Use Rotation
Enable this setting.
Wait #
Add Node > Base > Wait
We’ll wait for a frame (0 seconds) to give the prefab time to spawn.
- Time
Select Value > Value.
Set the value to 0.
Activate Damage Dealer #
Add Node > Battle > Action Outcome > Activate Damage Dealer
We’ll now activate the damage dealer on the spawned prefab (via the ability’s activation tags, which we’ll set up after this).
The damage dealer is placed on a disabled game object of the grenade prefab, but we can still activate it. We’ll later enable the game object when it’s time to do damage.
- Object (Activate On)
Select Prefab 0. - Activate
Enable this setting. - Use Action Tags
Enable this setting. - Set Action
Enable this setting.
Rigidbody Change Velocity #
Add Node > Game Object > Rigidbody > Rigidbody Change Velocity
Instead of adding a force, we’ll this time set the velocity that’s calculated to reach the position we want to hit.
This could be quite complicated, but luckily Makinom comes with the Shot Velocity Vector3 value selection to handle that for us with a few simple settings.
- Object (Rigidbody Object)
Select Prefab 0. - Vector3 Type
Select Physics > Shot Velocity. - Shot Type
Select Random.
This’ll create a random velocity between highest and lowest shot arc. - Speed
Select Value > Value.
Set the value to 8.
This matches the grenade throws maximum use range (which will be 8 as well). - Vector3 Type (Origin Position)
Select Game Object > Game Object. - Object
Select Prefab 0.
The shot is calculated from the spawned prefab’s position. - Vector3 Type (Target Position)
Select Game Object > Game Object. - Object
Select Starting Object.
The shot is calculated to the position that was selected.
Start Tagged Machine #
Add Node > Machine > Start Tagged Machine
We’ll now start a tagged machine on the grenade (spawned prefab) that’ll handle wait time and explosion for us without blocking the user any longer.
- Wait
Disable this setting.
We don’t need to wait for the machines to finish. - Object (Machine Object)
Select Prefab 0. - Use Same Object
Enable this setting.
The prefab will also be used as starting object of the tagged machine.
Click on Add Tag to add a starting tag.
- Tag
Set to grenade.
Wait #
Add Node > Base > Wait
We’ll now wait for the stored duration
- Time
Select Variable > Float Variable. - Variable Key
Set to wait. - Variable Origin
Select Local.
And that’s it for the schematic. Click on Save Schematic to save it, e.g. as GrenadeThrow.
Grenade Boom Schematic #
And the last schematic, handling the grenade’s explosion. It’ll be started by the tagged machine on the grenade.
We’ll mainly use activation and destruction of game objects and components this time. The grenade’s prefab has already everything set up, we just need to use it:
- enable it’s collider (after a short wait to not collide with the thrower)
- enable the explosion particle effect, unparent it and destroy it after time
- enable the damage dealer’s game object
Create a new schematic.
Wait #
Add Node > Base > Wait
We’ll wait for a short time to give the grenade enough time to leave the thrower’s game object.
- Time
Select Value > Value.
Set the value to 0.2.
Enable Component #
Add Node > Game Object > Component > Enable Component
We’ll enable the Sphere Collider component on the grenade (i.e. the Machine Object).
- Enable/Disable
Enable this setting. - Component Name
Set to SphereCollider. - Object
Select Machine Object.
Wait #
Add Node > Base > Wait
And we wait for another 3.3 seconds – i.e. the grenade will explode after 3.5 seconds.
- Time
Select Value > Value.
Set the value to 3.3.
Activate Object #
Add Node > Game Object > Game Object > Activate Object
We’ll now activate the BigExplosion child object, which is the explosion particle effect.
Activating (i.e. enabling) the game object will start it’s particle system and play the effect.
- Set Active
Enable this setting. - Object
Select Machine Object. - Child Object
Select Path.
We’ll define a path to a child object. - Find Child
Set to BigExplosion.
Destroy Object #
Add Node > Game Object > Game Object > Destroy Object
We’ll now mark the BigExplosion child object to be destroyed after 3 seconds.
We do this because we’ll also unmount the game object from the grenade next. The explosion should be visible longer than the grenade is alive (it’ll be destroyed shortly after doing damage).
- Object
Select Machine Object. - Child Object
Select Path. - Find Child
Set to BigExplosion. - Destroy After Time
Enable this setting. - Time
Set to Value > Value.
Set the value to 3.
Play Sound #
Add Node > Audio > Audio > Play Sound
We play an explosion sound on the explosion effect.
- Object (Play On)
Select Machine Object. - Child Object
Select Path. - Find Child
Set to BigExplosion. - Audio Clip Asset
Select ExplosionMetal. - Play One Shot
Enable this setting. - Set Pitch
Enable this setting. - Random Pitch
Enable this setting. - Pitch
Set to 0.8. - Pitch 2
Set to 1.2.
Mount Object #
Add Node > Game Object > Game Object > Mount Object
And now we’ll unmount the explosion from the grenade.
- Mount
Disable this setting. - Object
Select Machine Object. - Child Object
Select Path. - Find Child
Set to BigExplosion.
Activate Object #
Duplicate the previous Activate Object node, this time we activate the DamageDealer child object of the grenade.
The Damage Dealer component on it is already activated (from the throwing schematic) and will do damage after we activate it.
- Child Object
Select Path. - Find Child
Set to DamageDealer.
Wait #
Add Node > Base > Wait
And finally, we wait another short time.
The tagged machine we’ll set up on the grenade will automatically destroy the game object when it finishes, so this wait time is used to give the damage dealer enough time to do damage.
- Time
Select Value > Value.
Set the value to 0.1.
And that’s it for the schematic. Click on Save Schematic to save it, e.g. as GrenadeBoom.
Battle Range Template #
We’ll add a new battle range template for the grenade, which as a use range of 8.
Navigate to Templates > Battle Range Templates and add a new template.
- Name
Set Range 8.
Range Settings > Maximum Range #
- Maximum Range
Enable this setting. - Range
Select Value > Value.
Set the value to 8.
Grenade Item #
We can build upon the potion we set up in the last tutorial. The grenade will deal 50 damage to HP.
Navigate to Inventory > Items and copy the Potion item.
- Name
Set to Grenade. - Sprite (Icon)
Select icons_267.
Click on the Find TMP Tag button to get the icon’s tag for displaying it in texts (via text codes). This uses TextMesh Pro’s sprite asset setup.
Use Settings > Battle Settings > Reuse Settings #
We’ll change the reuse time to 5 seconds
- Reuse After
Select Value > Value.
Set the value to 5.
Target Selection Settings #
The grenade should damage all – and we’ll use a raycast (and cursor) to select a target position to throw to.
We’ll use a Custom target selection setup.
- Target Selection Type
Select Custom.
Target Settings #
- Target Type
Select All. - Target Range
Select None.
This is needed to have no regular target selection and use raycast targeting instead.
Raycast Settings #
- Use Target Raycast
Select Custom. - Raycast Type
Select Position.
We’ll raycast a position freely.
Otherwise, you can also limit positions on a defined grid or using game objects in the scene. - Layer Mask
Select only the Default layer.
First select Nothing, then the Default layer. - Clamp To Use Range
Enable this setting.
The raycasted position will stick to the use range instead of exceeding it. - Ray Origin
Select Screen.
The raycast will come from the screen (otherwise it can also come from the user’s game object).
We’ll use the Mouse/Touch Controls to select a position by clicking.
- Input Type
Select Both. - Mouse Button
Set to 0.
This uses the left mouse button.
We’ll use a Cursor Object to mark the position in the scene.
- Use Cursor
Enable this setting. - Prefab
Select GrenadeCursor.
Use Range Settings #
- Own Use Range
Enable this setting.
Click on Add Range.
- Range Type
Select Template. - Template
Select Range 8.
Target Settings > Target Changes > Target Change 0 > Status Change 0 #
Instead of adding 50, we’ll subtract 50 from HP.
- Operator
Select Sub.
Battle Animation > Battle Animation 0 #
- Schematic Asset
Select GrenadeThrow.
Battle Animation > Damage Dealer Settings #
Click on Add Tag.
- Tag
Set to boom.
This is the same activation tag we’ll used on the grenade’s prefab.
Click on Add Battle Animation. We’ll use the schematic we’ve set up to animate the damage dealer hit.
- Schematic Asset
Select DamageDealerHit.
Updating the Control Map #
We’ll now update the control map.
Navigate to Base/Control > Control Maps and select the Default control map.
Control Key 3 #
Click on Add Control Key.
Input Settings #
- Input Key
Select Grenade.
Action Settings #
- Type
Select Action. - Action
Select Item. - Item
Select Grenade. - 2nd Call Cancels Targeting
Enable this setting.
This lets us cancel the grenade target selection by pressing the grenade key again.
Conditions #
- During Target Selection
Enable this setting.
Otherwise we couldn’t cancel the target selection.
Updating Ellen #
We add a few grenades to Ellen’s start inventory.
Navigate to Combatants > Combatants and select Ellen.
Inventory & Equipment > Start Inventory #
Click on Add Item.
- Type
Select Item. - Item
Select Grenade. - Quantity
Select Value > Value.
Set the value to 20.
Battle Menu #
While we don’t use the battle menu, it’s still active in the background during things like the target selection – and also during our raycast targeting.
We make use of that and set the time scale to 0 while the battle menu is displayed.
Navigate to UI > Battle Menus and select the Default battle menu (this is already set up as the default battle menu in Battles > Battle System > General Settings).
- Change Time Scale
Enable this setting. - Time Scale
Set to 0.
Save Changes #
That’s it for the editor setup.
Don’t forget to save your changes by clicking on Save Settings at the bottom of the editor.
Cursor Prefab Setup #
We still need to set up our prefabs, we’ll start with the Grenade Cursor.
Open the GrenadeCursor prefab for editing – you can find it in Assets/Tutorial Assets/Prefabs/.
Auto Machine #
Add an Auto Machine component using the component menu.
Start Settings #
- Enable
Enable this setting.
The machine will start when the game object is enabled.
Machine Execution Settings #
- Schematic Asset
Select the CursorPulse schematic.
That’s it for the cursor prefab – save the changes.
Grenade Prefab Setup #
Open the Grenade prefab for editing – you can find it in Assets/Tutorial Assets/Prefabs/Weapons/.
Add Tagged Machine #
Add a Tagged Machine component to the prefab’s root using the component menu.
Start Settings #
Click on Add Starting Tag.
- Tag
Set to grenade.
Machine Execution Settings #
- Schematic Asset
Select the GrenadeBoom schematic. - Machine End Action
Select Destroy.
This’ll automatically destroy the grenade after the schematic finished.
Point Of Interest #
Add a Point Of Interest component to the prefab’s root using the component menu.
This component will be detected by the move AI and let the enemies move toward it – i.e. we’ll lure them to the grenade to get blown up!
- Schematic Asset
Select the IdleWait schematic.
This is the same schematic we used for the move AI’s idle behaviour.
The combatant will use the schematic when reaching the PoI. - Wait
Enable this setting.
The combatant will wait for the schematic to finish.
Add Damage Dealer #
Add a Damage Dealer component to the disabled DamageDealer child object of the prefab using the component menu.
- Start Type
Select Trigger Enter. - One Time Damage
Enable this setting.
Activation Settings #
If you remember, we used the activate tag boom in the grenade item, so we need to use that here as well.
- Field
Enable this setting. - All Battle Systems
Enable this setting.
Click on Add Activation Tag.
- Activation Tag
Set to boom.
And that’s it for the grenade prefab’s setup – save the changes.
Testing #
Hit play and throw some grenades.
Remember, the grenade key is E.
Selecting a position to throw to works – stops the time and the cursor pulsates
And enemies (that don’t have a target) are lured to it through the Point Of Interest component.
And killed – great!
Next, we’ll set up a HUD to show our available items.