Effect
Note that there is a machine gun in the scene. As long as the tank we control enters the machine gun's perception range, the machine gun will automatically lock the position of the tank and fire.
step
1. First create an Actor class blueprint, that is, an automatic machine gun, which only includes a static mesh and a spherical collision component. The spherical collision component is used as the perception range of the machine gun
When the specified Actor appears within the scope of the spherical collision component, set the Boolean variable "isShoot" to True, and then execute the custom aiming event
The automatic aiming event is as follows, which is executed every 0.2s, and the returned handle is promoted to a variable, and then the position of the actor controlled by the player and the position of the machine gun itself are obtained
Calculate the angle the machine gun needs to rotate
When the component finishes overlapping, set "isShoot" to False, then clear the timer handle
Execute fire when the event starts running
The firing logic is as follows, only fire when "isShoot" is True, and then generate bullets at the slot
Generate muzzle flame particle effects
The final effect is as shown at the beginning of the article.