Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revisionBoth sides next revision | ||
quick:program [2018/05/18 21:22] – pedro | quick:program [2018/05/18 21:25] – pedro | ||
---|---|---|---|
Line 104: | Line 104: | ||
- Create a new node in the canvas for the `ShootOnce` action. Note the action parameters in the inspector and, specifically, | - Create a new node in the canvas for the `ShootOnce` action. Note the action parameters in the inspector and, specifically, | ||
- | ![Our action in the Collection, and its parameters in the inspector](images/ | + | {{ :images:program:FirstActionInTheCollection.png |
- We want the shooting parameters to be available in the inspector of those game objects that use the behavior. Select _blackboard_ for all the three input parameters, and create a new field for each one. Use the default names except for `velocity`, where something like `bulletVelocity` is preferred to avoid confusion. | - We want the shooting parameters to be available in the inspector of those game objects that use the behavior. Select _blackboard_ for all the three input parameters, and create a new field for each one. Use the default names except for `velocity`, where something like `bulletVelocity` is preferred to avoid confusion. | ||
- The `velocity` default value has vanished. Keep in mind that it is only used when the parameter is set _using a constant_ in the editor. When using a blackboard parameter, the default value specified in the code attribute is discarded. Fortunately, | - The `velocity` default value has vanished. Keep in mind that it is only used when the parameter is set _using a constant_ in the editor. When using a blackboard parameter, the default value specified in the code attribute is discarded. Fortunately, | ||
- | ![`ShootOnce` blackboard parameters](images/ | + | {{ :images:program:ShootOnceBlackboardParameters.png |
- Connect the priority selector and the `ShootOnce` action so that shooting is the first child to be considered (higher priority). | - Connect the priority selector and the `ShootOnce` action so that shooting is the first child to be considered (higher priority). | ||
- Right click on the default guard `AlwaysTrue` of the `ShootOnce` node, select `Replace with ...` and choose `Perception/ | - Right click on the default guard `AlwaysTrue` of the `ShootOnce` node, select `Replace with ...` and choose `Perception/ | ||
- | ![Complete behavior using the `ShootOnce` action](images/ | + | {{ :images:program:BBUsingShootOnce.png |
- Close the editor. We will now create the bullet prefab that will be cloned each time the enemy shoots: | - Close the editor. We will now create the bullet prefab that will be cloned each time the enemy shoots: | ||
Line 120: | Line 120: | ||
- Change the scale to (0.3, 0.3, 0.3) and the rotation to (90, 0, 0) so it will lay horizontally. | - Change the scale to (0.3, 0.3, 0.3) and the rotation to (90, 0, 0) so it will lay horizontally. | ||
- Add it a new C# script and change the `Start()` method so the bullet autodestroys itself after two seconds: | - Add it a new C# script and change the `Start()` method so the bullet autodestroys itself after two seconds: | ||
+ | - Drag and drop the `Bullet` into the Project panel so a new prefab is created based on it, and remove the game object. | ||
<code csharp> | <code csharp> | ||
Line 127: | Line 128: | ||
</ | </ | ||
- | |||
- | - Drag and drop the `Bullet` into the Project panel so a new prefab is created based on it, and remove the game object. | ||
- Now we must create the shooting point. We will create a child node in the `Enemy` game object, that will be placed in the middle of his front face. When the enemy moves, so do the shooting point. | - Now we must create the shooting point. We will create a child node in the `Enemy` game object, that will be placed in the middle of his front face. When the enemy moves, so do the shooting point. | ||
Line 181: | Line 180: | ||
Although our action just shoots a bullet, if you have played the scene you will have noticed that the enemy shoots a high-frequency stream of bullets. | Although our action just shoots a bullet, if you have played the scene you will have noticed that the enemy shoots a high-frequency stream of bullets. | ||
- | ![Final behavior using the `ShootOnce` action](images/ | + | {{ :images:program:ShootOnceFinalyBT.png |
Our `ShootOnce` action ends immediately after instantiating the bullet. That causes _the end of the parent_ priority selector. Fortunately, | Our `ShootOnce` action ends immediately after instantiating the bullet. That causes _the end of the parent_ priority selector. Fortunately, |