<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[Shooter Game Tutorial]]></provider_name><provider_url><![CDATA[http://shootertutorial.com]]></provider_url><author_name><![CDATA[andrzejkoloska]]></author_name><author_url><![CDATA[https://shootertutorial.com/author/andrzejkoloska/]]></author_url><title><![CDATA[Creating Shotgun]]></title><type><![CDATA[link]]></type><html><![CDATA[<p><a href="http://shootertutorial.com/2015/06/18/creating-a-shotgun/"><img class="alignnone wp-image-499 size-large" src="https://shootertutorial.files.wordpress.com/2015/06/screen-shot-2015-06-18-at-14-01-27.png?w=1024&#038;h=748" alt="Screen Shot 2015-06-18 at 14.01.27"   /></a></p>
<p>In <a href="http://shootertutorial.com/2015/06/14/how-to-do-damage-advanced/" target="_blank">earlier post </a>we have added shooting functionality for base weapon. Now let&#8217;s upgrade this class to support Shotgun that came with <a href="https://www.unrealengine.com/content/b5db9911879141e99f8c34fb14b66691" target="_blank">Military Weapons Silver</a> package.</p>
<ul>
<li>Shotgun will fire more bullets than other weapons, (Burst functionality)</li>
<li>Its single shoot shotgun with automatic reloading, (custom reload functionality)</li>
<li>Spread will be different,</li>
<li>Impulse for ragdoll will be different, (Add ImpulsePower to BaseWeapon)</li>
<li>Custom animation for FPP Hands to carry shotgun,</li>
</ul>
<p><!--more--></p>
<pre><strong>This Tutorial has been created using Unreal Engine 4.8.2</strong>. 
Make sure you are working on the same version of the engine.</pre>
<p><strong>Updating BP_BaseWeapon</strong></p>
<p>Open BP_BaseWeapon and add those variables:</p>
<ul>
<li>PullDownWhenReloading (bool, default: true)<br />
Basically shotgun from the pack comes with reload animation so we don&#8217;t want to put hands down while reloading as in other weapons,</li>
<li>BurstCount (int, default: 1)<br />
It will tell us how many bullets we should fire on one Fire Event,</li>
<li>ImpulseOnKill (float, default: 10 000)<br />
This will be used for ragdoll impulse on die,</li>
</ul>
<p>Now in Fire function let&#8217;s add BurstCount:</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/06/burstcountforloop.jpg" target="_blank"><img class="alignnone wp-image-502 size-large" src="https://shootertutorial.files.wordpress.com/2015/06/burstcountforloop.jpg?w=1024&#038;h=653" alt="BurstCountForLoop"   /></a></p>
<hr />
<p><strong>Updating GameplayCharacter</strong></p>
<p>Now we need to update Reload event in GameplayCharacter to check if weapon should be putted down when reloading.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/06/pulldownwhenreloading.jpg"><img class="alignnone size-medium wp-image-503" src="https://shootertutorial.files.wordpress.com/2015/06/pulldownwhenreloading.jpg?w=300&#038;h=115" alt="PullDownWhenReloading" width="300" height="115" /></a></p>
<p>I marked new nodes.</p>
<p>Add new event dispatcher: Shotgun_IsReloading with one input: IsReloading (bool) it will be used to communicate with animation blueprint. It will be called each time reloading animation will be played.</p>
<hr />
<p><strong>Creating Shotgun Blueprint.</strong></p>
<p>Create new Blueprint extending from BP_BaseWeapon. Name it BP_Weapon_Shotgun. Check variables:</p>
<ul>
<li>CurrentAmmoInMag: 1,</li>
<li>MaxAmmoInMag: 1<br />
It means that we have only one bullet before reloading.</li>
<li>CurrentAmmoInBackpack: 15,</li>
<li>MaxAmmoInBackpack: 15,</li>
<li>ReloadTime: 0.7,</li>
<li>SpreadMin: 0.1,</li>
<li>SpreadMax: 1,</li>
<li>SpreadCurrent: 0.1,</li>
<li>SpreadDecreaseTime: 0.4,</li>
<li>MinWeaponDamageModifier: 0.4,</li>
<li>MaxWeaponDamageModifier: 0.7,</li>
<li>PullDownWhenReloading: false,</li>
<li>BurstCount: 10,</li>
<li>ImpulseOnKill: 50 000,</li>
</ul>
<p>So we are just setting up variables. Event graph is just used to play Fire animation which is available in the package.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/06/shotguneventgraph.jpg"><img class="alignnone size-medium wp-image-504" src="https://shootertutorial.files.wordpress.com/2015/06/shotguneventgraph.jpg?w=300&#038;h=146" alt="shotguneventgraph" width="300" height="146" /></a></p>
<p>In this example we will drive whole firing and reloading using Anim Notifies.</p>
<hr />
<p><strong>Firing and reloading</strong></p>
<p><a href="https://docs.unrealengine.com/latest/INT/Engine/Animation/Sequences/Notifies/index.html" target="_blank">Animation Notifies</a> are great thing and we will use one here.</p>
<p>Create new Blueprint extending from AnimNotify and name it Shotgun_SetReloading.</p>
<p>Open it and create one variable:</p>
<ul>
<li>IsReloading (bool, editable)</li>
</ul>
<p>Now we need to override Received Notify function.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/06/notify.jpg"><img class="alignnone size-medium wp-image-505" src="https://shootertutorial.files.wordpress.com/2015/06/notify.jpg?w=300&#038;h=107" alt="Notify" width="300" height="107" /></a></p>
<p>If you open Fire animation (Fire_Shotgun_W) you can add notify when weapon is in place where animation is reloading the weapon.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/06/notifyadded1.jpg"><img class="alignnone size-medium wp-image-513" src="https://shootertutorial.files.wordpress.com/2015/06/notifyadded1.jpg?w=300&#038;h=80" alt="notifyadded" width="300" height="80" /></a></p>
<p>If you select added notify you can change IsReloading bool value. The first one should be true and next false &#8211; it means that it will finish reloading in place where animation is telling this.</p>
<p>You can create shell particle as we <a href="http://shootertutorial.com/2015/06/10/fx-create-ammo-shell-particle-from-mesh/">did earlier for pistol</a>. And you can add PlayParticlEffect notify to spawn it using animation!</p>
<p>Now your weapon should have firing and reloading functionality.</p>
<hr />
<p><strong>Creating hands animations.</strong></p>
<p>This is the hardest part but you have learnt a lot about TwoBoneIK and Transform (Modify) Bone in earlier posts. Go to HeroFPP_AnimationBlueprint and add those variables:</p>
<ul>
<li>ShotgunRecoil (bool),</li>
<li>ShotgunReloading (bool),</li>
<li>ShotgunRecoilAlpha (float),</li>
</ul>
<p>Now in Event Blueprint Initialize Animation let&#8217;s bind Shotgun_IsReloading from GameplayCharacter.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/06/animbp_beginplay.jpg"><img class="alignnone size-medium wp-image-507" src="https://shootertutorial.files.wordpress.com/2015/06/animbp_beginplay.jpg?w=300&#038;h=85" alt="animbp_beginplay" width="300" height="85" /></a></p>
<p>In UpdateAnimation add another pin to Sequence and add ShotgunRecoilAlpha interpolation.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/06/recoilinterpolation.jpg"><img class="alignnone size-medium wp-image-508" src="https://shootertutorial.files.wordpress.com/2015/06/recoilinterpolation.jpg?w=300&#038;h=127" alt="recoilinterpolation" width="300" height="127" /></a></p>
<p>Now in Animation Graph. I won&#8217;t tell you exactly what to do here &#8211; you should be able to do it by yourself if you read earlier posts.</p>
<p>Here is my ShotgunIdle Pose. Just using Transform (Modify) Bones to move hands so they fit Shotgun. You should read <a href="http://shootertutorial.com/2015/06/08/how-to-add-weapons-basics-equipping/" target="_blank">How to Add Weapons</a>  if you don&#8217;t have shotgun placeholder animation here when you change CurrentWeapon enum in animation blueprint preview.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/06/shotgunidle.jpg"><img class="alignnone size-medium wp-image-509" src="https://shootertutorial.files.wordpress.com/2015/06/shotgunidle.jpg?w=300&#038;h=46" alt="shotgunidle" width="300" height="46" /></a></p>
<p>Now I&#8217;m blending the Idle pose by bool (recoil)</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/06/blendbybool.jpg"><img class="alignnone size-medium wp-image-510" src="https://shootertutorial.files.wordpress.com/2015/06/blendbybool.jpg?w=300&#038;h=86" alt="blendbybool" width="300" height="86" /></a></p>
<p>Last node goes to earlier created blend poses by Current Weapon enum.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/06/lastscreen.jpg"><img class="alignnone size-medium wp-image-511" src="https://shootertutorial.files.wordpress.com/2015/06/lastscreen.jpg?w=300&#038;h=253" alt="lastscreen" width="300" height="253" /></a></p>
<p>Take your time with using modify bone. Thanks to Epic you have preview and you can check out everything what you are doing if you don&#8217;t have any cast to nodes in your graph!</p>
<hr />
<p>Here&#8217;s the final result:</p>
<p><span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='640' height='390' src='https://www.youtube.com/embed/l-Efsj5XG6k?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0' allowfullscreen='true'></iframe></span></p>
<p>Time Spent on writing this tutorial: 4h.</p>
<blockquote><p>Creating ShooterTutorial takes a lot of my free time.<br />
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=8UXM3JZGDPPPE"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Buy Now Button" /><br />
</a>If you want you can help me out! I will use your donation to buy better assets packs and you will be added to Credits /Backers page as well.</p>
<p>Implementing game is taking time but writing about this is taking much more effort!</p></blockquote>
]]></html><thumbnail_url><![CDATA[https://i2.wp.com/shootertutorial.files.wordpress.com/2015/06/notifyadded1.jpg?fit=440%2C330]]></thumbnail_url><thumbnail_height><![CDATA[116]]></thumbnail_height><thumbnail_width><![CDATA[440]]></thumbnail_width></oembed>