How To Create & Script Character Projectile/Weapon Unreal Engine 4

First, we will create and script a projectile. Create a new Actor Blueprint, go to Content Browser > click RMB > select Blueprint Class > Actor Blueprint, for example purposes, let's call it MyProjectileBp, add three components a ProjectileMovement, a Box Collision and a Cylinder Static Mesh.

Select the ProjectileMovement component, in the Details panel under Projectile, set an Initial speed of 16000, you can change it in the future if you think is to fast, check the box Rotation Follows Velocity, set the Projectile Gravity Scale to 0. Position the Cylinder mesh in the Box Collision, to fit the box. Select the Box Collision, in the Details Panel under Collision, check the box Simulation Generates Hit Events, for the Collision Presets select OverlapAllDynamic. Select the Cylinder mesh, you can add an emissive material to it if you have one, if not, no problem, in the Details Panel under Collision, check the box Simulation Generates Hit Events, for the Collision Presets you need to make a custom collision in which you BlockAll, but Ignore PhysicsBody.

Now, we will start scripting the Projectile. In the Editor Graph, add an Event Hit node, drag of it to add a Branch node, add an Is Simulating Physics node with Box collision as the scene component, connect the Return Value pin with the Condition pin of the Branch node, connect the Other Comp pin of the Event Hit node with the Target pin of the Is Simulating Physics node, add to the string an Add Impulse at Location node, then add a Destroy Actor node. In the Graph, add a Get Velocity node and a Get Actor Location node, connect the Get Actor Location node with the Location pin of the Add Impulse at Location node, drag of the Get Velocity node to add a vector * float node (Scales Vector A by B), in the scale pin type 10, then connect the string with the Impulse pin of the Add Impulse at Location node. Now, the projectile is ready.

Let's set up a weapon for the Character, or better said, a spot from where to shoot the projectile. Open the Character Blueprint and add a Sphere Collision as a component, position the Sphere in the Viewport in the exact spot from where you want your character to shoot projectiles.

Go to Editor Graph, create a new variable of struct Vector type, call it Gun Offset, add an InputAction Fire event node and an InputTouch Event node, connect both event nodes to a Spawn Actor node, with the Class set to MyProjectileBp, the Collision Handling Override set to Try To Adjust Location, Don't Spawn If Still Colliding, next add a Play Sound at Location node with the Location pin connected to a Get Actor Location node, then select a sound (this wll play a sound every time we fire a projectile), connect the Play Sound at Location node to a Set Life Span node, connect the Return value pin of Spawn Actor node with the Target pin of Set Life Span node.

Drag of the Finger Index pin of the InputTouch Event node to add a Touch 1 node, connect it to the Condition pin of a Branch node, drag of the True pin of the Branch node and connect it to the Spawn Actor node.

Next, add a reference in the Graph to the Camera and the Sphere Collision box, each of the references connected to a GetWorldRotation node, add a Get reference to the Gun Offset variable and connect it to RotateVector node, connect the GetWorldRotation node of the Camera with the B pin of the RotateVector node, add a vector + vector node, connect the GetWorldRotation node of the Sphere with the A pin of the vector + vector node, connect the RotateVector node with the B pin of the vector + vector node, connect the end pin of the vector + vector node with a Make Transform node, connect the GetWorldRotation node of the Camera with the Rotation pin of the Make Transform node.

Drag of the end pin of the Make Transform node to add a Select node, add a reference to the Using Motion Controllers? Boolean variable, if you do not have one by default you need to create one, connect the Boolean variable with the Index pin of the Select node, then connect the Select node with the Spawn Transform pin of the Spawn Actor node. Now, your Character should be able to shoot projectiles without any problems.

Tip! If you want your Character to shoot projectiles from multiple spots, you can add another Sphere collision at a new spot, copy the entire string from above and just replace the reference to the Sphere collision with the reference to the new Sphere collision, then, everything should work just fine.

- - - - - - - - - - - -

Interesting articles to read on Edvog.com
Unreal Engine 4 Beginner's Guide
Unreal Engine 4 Tutorials & How To's (With Pictures & Video)
Blender 3D Beginner's Guide
GIMP Beginner's Guide

- - - - - - - - - - - -

About Edvog.com - Music, Games & Educational Resources (Information, Health, Medicine & Research) by Edvog.com

My name is Andrei Ionita, I am the creator and owner of Edvog.com website, I am also the creator and owner of all of the products associated with it, such as: music, games, videos and more...

I like to write articles about everything I find interesting in this world. The entire content found on this website is fact checked and original, when I post something, I try to double check all the information provided against all the reliable and trustworthy sources that I can find. On this website you may find content about medicine, the purpose of this type of content is simply informational and is not intended to be a substitute for professional medical advice, for questions you may have regarding your health, always seek the guidance of your doctor or other qualified health professional.

About entertainment and media - Beside, being a website owner and content writer, I'm also a game developer, music producer and video creator. I create, video games, music, animations, photos and more, this is why, from time to time, I will also post content about entertainment and media industry (a broad terminology, just to cover everything in the category)

You can check out the games made by me on Steam and on Google Play, if want to listen my music you can check out my Youtube channel, Spotify profile, iTunes profile, Google Play Music profile, etc. Who knows? Maybe your next favorite game or song will be created by me :)

If you want to support my work, you can play the games created by me, listen to my music and/or Make A PayPal Donation, whatever form of support you will choose, I thank you and wish you a nice day!

Edvog.com / AI Edvog / Andrei Ionita on the internet

YoutubeSpotifyApple MusicAmazon MusicGoogle Play MusicGoogle PlaySteamSupport My Work Make A PayPal Donation