I will explain the enemy bullet launching in this tutorial.
Enemy3 ‘s ArborFSM does not fire enemy bullet directly, but indirectly controls Weapon of child object.
From Ememy3 to fire command
Please look at the Shot state of Enemy3.
SendTrigger sends a trigger to Weapon, and the message is set to “ShotTrigger”.
On Weapon side, this “ShotTrigger” is triggered to control enemy bullet shooting.
For more information on SendTrigger, see Arbor reference “SendTrigger”.
Firing process by Weapon
Please select the Weapon object in the child of Enemy3 and look at the Arbor Editor.
The “ShotTrigger” message comes in when the TriggerTransition used for the Start state comes.
In the Stop resident state, it waits for the “StopTrigger” message, and when a message comes, it instantaneously transits to the Start state.
For more information on TriggerTransition, see Arbor reference “TriggerTransition”.
In this way, by using SendTrigger and TriggerTransition, it becomes possible to create a mechanism to link objects.
LookAt2DObjectWithTag used in the Rotation resident state is the StateBehaviour this time created for 2D Shooting Game.
It is a script that turns the Transform specified in the Transform field to the object direction specified by Tag.
This time we are realizing our aim by bringing Weapon to the player direction.
About Shot state
In the Shot state, an EnemyBullet prefab is generated from ShotPosition1 and ShotPosition2 using InstantiateGameObject.
Then wait for 0.5 seconds with TimeTransition and continue to generate EnemyBullet repeatedly.
In the EnemyBullet object, I move it using SetVelocityRigidbody2D.