So I had to leave my home for 2 weeks. Big deal! No time for further intros - time to get back to work.
I took a small detour towards UE animation tweaking after seeing my mannequin's thumbs clip into the shotgun it was holding. Turns out the game-making platform has animation tools identical to Blender's - pick a bone's movements and set keyframes to instruct the system how it is moved frame by frame. Press S to save every change on your default pose mesh.
Back onto the tutorial track, a gun is expected to shoot bullets, so we have to create the logic that happens within the Engine. The aforementioned blueprints from earlier do that for us. I first needed to create an Actor Blueprint. An Actor is any object that can be placed into a level, such as a Camera, static mesh, or player start location. The purpose of my first Actor blueprint is to tell how each spawned bullet should behave during run time.
An essential component in it is the Projectile Movement, which enforces on the bullet mesh its physical properties, simulation elements, etc. Here is where you can make your projectiles like bouncy tennis balls or gravity-defying Bullet Bills.
Once you got the bullets working as you want them, you can instruct how the thing that shoots them out and where it shoots them. By "the thing", I mean the shotgun. Such an instruction can be done by adding a child Arrow component to the shotgun.
Akin to how a toy robot needs commands from an input to perform specified actions, an Input Mapping Context (IMC) is needed for an Actor (your player character) to execute blueprints and scripts. In a Starter IMC are 3 input actions (IAs) for vertical ascension, horizontal movement, and camera control. I had to add a 4th IA for shotgun-blasting triggered by clicking the left mouse button.
With the IA setup complete, I switched to my mannequin's event graph. Inside my player's graph is a series of non-coding, input-triggered event scripts, each containing linked command nodes for the engine to execute per input. For the sake of organization, I made a Comment box to contain my nodes for the new shooting IA.
Below is a dummy's rundown of the fully actualized script (see the 3rd image):
Left mouse button is clicked, which spawns the scripted bullet Actor a la SpawnActor node.
The Arrow acting as the bullet's spawn location will have its axis location data extracted by SpawnActor.
Note: this engine's Arrow's location data refers to its the edge of its flat rear end, not the triangular end.
SpawnActor spawns the bullet and the bullet acts out its blueprint's commands.
Note: Collision Handing Override governs the spawn point's relations with external overlapping elements.
Note: Option 'Always Spawn, Ignore Collisions' allows the node to spawn Actors regardless of overlap/collision with overlap-able elements.
Your shotgun can now fire bullets now. That is desirable… if the spawned projectiles did not impact the game's performance and workload. Without another command to despawn the bullets, they will remain in the instance and harass your computer until the next restart.
The step to make each bullet despawn upon collision requires backpedaling to the bullet blueprint. Over that place, I added two new nodes to make each projectile disappear upon contact: Event Hit and Destroy Actor. The names tell you everything about the roles of these nodes.
The step to finishing my bullet logic requires backpedaling to the bullet blueprint. Over that place, I added two new nodes to make each projectile disappear upon contact: Event Hit and Destroy Actor. The names tell you everything about the roles of these nodes.
A few personal tweaks to bullet behavior and there you have it: a function shotgun… that behaves like a semi-auto rifle. I can fix that later; all the basics have been finally implemented!